text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int vis[50];
int ask(int c, int d) {
cout << "? " << c << " " << d << endl;
int res;
cin >> res;
return res;
}
int main(void) {
int i, j, n, m, C, D, resc, resd, T, MOST;
C = D = 0;
MOST = 29;
T = 0;
memset(vis, 0, sizeof(vis));
while (1) {
m = ask(C, D);
T = 0;
for (i = 0; i <= MOST; i++) {
T += (1 << i);
}
if (m == 1) {
while (MOST >= 0 && ask(T + C, T + D) == -1) {
T -= (1 << MOST);
MOST--;
}
C += (1 << (MOST + 1));
vis[MOST + 1] = 1;
MOST--;
} else if (m == -1) {
while (MOST >= 0 && ask(T + C, T + D) == 1) {
T -= (1 << MOST);
MOST--;
}
D += (1 << (MOST + 1));
vis[MOST + 1] = 1;
MOST--;
} else {
MOST = 29;
while (MOST >= 0) {
if (vis[MOST]) {
MOST--;
continue;
}
T = (1 << MOST);
if (ask(T + C, D) == -1) {
C += (1 << (MOST));
D += (1 << (MOST));
}
MOST--;
}
break;
}
}
cout << "! " << C << " " << D << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
long long t = 30;
int main() {
cout << "? 0 0" << endl;
long long a = 0;
long long b = 0;
int d = 0;
cin >> d;
for (int(i) = 0; (i) < (int)(t); (i)++) {
if (d == 1) {
cout << "? " << (a + (1 << (t - 1 - i))) << " " << b << endl;
int ans = 1;
cin >> ans;
cout << "? " << (a + (1 << (t - 1 - i))) << " "
<< (b + (1 << (t - 1 - i))) << endl;
int ans2 = 1;
cin >> ans2;
if (ans == 0) {
a += (1 << (t - 1 - i));
d = 0;
}
if (ans == 1 && ans2 == 1) {
d = 1;
}
if (ans == 1 && ans2 == -1) {
a += (1 << (t - 1 - i));
d = 1;
}
if (ans == -1 && ans2 == 1) {
a += (1 << (t - 1 - i));
b += (1 << (t - 1 - i));
d = 1;
}
if (ans == -1 && ans2 == -1) {
a += (1 << (t - 1 - i));
d = -1;
}
} else if (d == 0) {
cout << "? " << (a + (1 << (t - 1 - i))) << " " << b << endl;
int ans = 1;
cin >> ans;
cout << "? " << (a + (1 << (t - 1 - i))) << " "
<< (b + (1 << (t - 1 - i))) << endl;
int ans2 = 1;
cin >> ans2;
if (ans == 1) {
} else {
a += (1 << (t - 1 - i));
b += (1 << (t - 1 - i));
}
} else {
cout << "? " << a << " " << (b + (1 << (t - 1 - i))) << endl;
int ans = 1;
cin >> ans;
cout << "? " << (a + (1 << (t - 1 - i))) << " "
<< (b + (1 << (t - 1 - i))) << endl;
int ans2 = 1;
cin >> ans2;
if (ans == 0) {
b += (1 << (t - 1 - i));
d = 0;
}
if (ans == 1 && ans2 == -1) {
a += (1 << (t - 1 - i));
b += (1 << (t - 1 - i));
d = -1;
}
if (ans == 1 && ans2 == 1) {
b += (1 << (t - 1 - i));
d = 1;
}
if (ans == -1 && ans2 == 1) {
b += (1 << (t - 1 - i));
d = -1;
}
if (ans == -1 && ans2 == -1) {
d = -1;
}
}
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 10;
int ask(int c, int d) {
printf("? %d %d\n", c, d);
fflush(stdout);
int res;
scanf("%d", &res);
return res;
}
int main() {
int a = 0, b = 0;
int last = ask(a, b);
for (int i = 29; i >= 0; i--) {
int res1 = ask(a | (1 << i), b), res2 = ask(a, b | (1 << i));
if (res1 == res2) {
if (last == 1)
a |= (1 << i);
else
b |= (1 << i);
last = res1;
} else if (res1 == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
inline int query(int c, int d) {
printf("? %d %d\n", c, d);
fflush(stdout);
int res;
scanf("%d", &res);
return res;
}
void workEqual(int d, int a, int b) {
for (; ~d; --d) {
if (query(a | (1 << d), b) == -1) a |= 1 << d, b |= 1 << d;
}
printf("! %d %d\n", a, b);
}
int main() {
int a = 0, b = 0;
int r = query(a, b);
if (r == 0) {
workEqual(29, a, b);
return 0;
}
for (int i = 29; ~i; --i) {
if (r == 1) {
int t = query(a, b | (1 << i));
if (t == 0) {
a |= 1 << i;
workEqual(i - 1, a, b);
return 0;
} else if (t == 1) {
a |= 1 << i;
int t2 = query(a, b);
if (t2 == -1) b |= 1 << i;
} else {
int t2 = query(a | (1 << i), b);
if (t2 == -1) r = -1, a |= 1 << i;
}
} else {
int t = query(a | (1 << i), b);
if (t == 0) {
b |= 1 << i;
workEqual(i - 1, a, b);
return 0;
} else if (t == 1) {
int t2 = query(a, b | (1 << i));
if (t2 == 1) r = 1, b |= 1 << i;
} else {
b |= 1 << i;
int t2 = query(a, b);
if (t2 == 1) a |= 1 << i;
}
}
}
printf("! %d %d\n", a, b);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const int MOD = 1000000007;
void print(int x) {
cout << x << endl;
exit(0);
}
void PRINT(string x) {
cout << x << endl;
exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int Q(int x, int y) {
printf("? %d %d\n", x, y);
fflush(stdout);
cin >> x;
return x;
}
signed main() {
int a = 0, b = 0, t = Q(0, 0), x, y, i = 1 << 30;
while (i >>= 1) {
x = Q(a | i, b);
y = Q(a, b | i);
if (x == y)
(t > 0 ? a : b) |= i, t = x;
else if (!~x)
a |= i, b |= i;
}
printf("! %d %d", a, b);
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXB = 30;
int query(bitset<MAXB> a, bitset<MAXB> b) {
cout << "? " << a.to_ulong() << ' ' << b.to_ulong() << endl;
int t;
cin >> t;
return t;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
bitset<MAXB> curA(0), curB(0);
int aBigger = 0;
bool needUpdate = true;
vector<int> ans;
for (int i = MAXB - 1; i >= 0; i--) {
if (needUpdate) aBigger = query(curA, curB);
if (aBigger == 0) {
for (; i >= 0; i--) {
ans.push_back(0);
}
break;
}
curA.flip(i);
curB.flip(i);
int res = query(curA, curB);
if (res != aBigger) {
if (aBigger == 1) {
ans.push_back(1);
} else {
ans.push_back(-1);
}
curA.flip(i);
needUpdate = true;
} else {
ans.push_back(0);
needUpdate = false;
}
}
bitset<MAXB> finalA(0), finalB(0);
reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
if (ans[i] == 1) {
finalA[i] = 1;
finalB[i] = 0;
} else if (ans[i] == -1) {
finalA[i] = 0;
finalB[i] = 1;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
if (ans[i] == 0) {
finalB.flip(i);
int res = query(finalA, finalB);
if (res == 1) {
finalA[i] = 1;
finalB[i] = 1;
} else {
finalA[i] = 0;
finalB[i] = 0;
}
}
}
cout << "! " << finalA.to_ulong() << ' ' << finalB.to_ulong() << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a = 0, b = 0;
bool gr = 0;
cout << "? " << 0 << " " << 0 << endl;
fflush(stdout);
int g;
cin >> g;
if (g == 1)
gr = 1;
else
gr = 0;
for (int i = 29; i >= 0; i--) {
cout << "? " << (a + (1 << i)) << " " << b << endl;
fflush(stdout);
int a1, a2;
cin >> a1;
cout << "? " << a << " " << (b + (1 << i)) << endl;
fflush(stdout);
cin >> a2;
if (a1 == a2) {
if (gr) {
a += (1 << i);
if (a1 == 1)
gr = 1;
else
gr = 0;
} else {
b += (1 << i);
if (a1 == 1)
gr = 1;
else
gr = 0;
}
}
if (a1 != a2) {
if (a1 == -1) {
a += (1 << i);
b += (1 << i);
}
}
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
cout << "? " << c << ' ' << d << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
int a = 0, b = 0, big = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
if (f == s) {
if (big == 1)
a ^= (1 << i);
else
b ^= (1 << i);
big = f;
} else if (f == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << ' ' << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int query(int c, int d) {
int res;
cout << "? " << c << ' ' << d << endl;
fflush(stdout);
cin >> res;
return res;
}
int main() {
int a = 0, b = 0;
bool op = (query(0, 0) > 0);
for (int i = 29; i >= 0; i--) {
int q1 = query(a ^ (1 << i), b), q2 = query(a, b ^ (1 << i));
if (q1 == q2) {
if (op == 1)
a ^= (1 << i);
else
b ^= (1 << i);
op = (q1 == 1);
} else if (q1 == -1 && q2 == 1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << ' ' << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b, st, zero;
int d = (1 << 30) - 1;
int main() {
a = 0, b = 0;
puts("? 0 0");
fflush(stdout);
scanf("%d", &zero);
for (int i = 29; i >= 0; --i) {
if (zero == 0) {
printf("? %d %d\n", a | (1 << i), b);
fflush(stdout);
scanf("%d", &st);
if (st == -1) a |= 1 << i, b |= 1 << i;
} else {
printf("? %d %d\n", a | (1 << i), b | (1 << i));
fflush(stdout);
scanf("%d", &st);
if (st == zero) {
printf("? %d %d\n", a | (1 << i), b);
fflush(stdout);
scanf("%d", &st);
if (st == -1) a |= 1 << i, b |= 1 << i;
} else {
if (st == 1)
b |= 1 << i;
else
a |= 1 << i;
printf("? %d %d\n", a, b);
fflush(stdout);
scanf("%d", &zero);
}
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
cout << "? " << c << ' ' << d << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
int a = 0, b = 0, big = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
if (f == s) {
if (big == 1)
a ^= (1 << i);
else
b ^= (1 << i);
big = f;
} else if (f == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << ' ' << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double pi = acos(-1.0);
const int maxn = 100000 + 10;
const int mod = 1e9 + 7;
inline char _getchar() {
static const int BUFSIZE = 100001;
static char buf[BUFSIZE];
static char *psta = buf, *pend = buf;
if (psta >= pend) {
psta = buf;
pend = buf + fread(buf, 1, BUFSIZE, stdin);
if (psta >= pend) return -1;
}
return *psta++;
}
inline int read(int &x) {
x = 0;
int f = 1;
char ch = _getchar();
while ((ch < '0' || ch > '9') && ~ch) {
if (ch == '-') f = -1;
ch = _getchar();
}
if (ch == -1) return -1;
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = _getchar();
}
x *= f;
return 1;
}
inline int read(long long &x) {
x = 0;
int f = 1;
char ch = _getchar();
while ((ch < '0' || ch > '9') && ~ch) {
if (ch == '-') f = -1;
ch = _getchar();
}
if (ch == -1) return -1;
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = _getchar();
}
x *= f;
return 1;
}
inline int read(double &x) {
char in;
double Dec = 0.1;
bool IsN = false, IsD = false;
in = _getchar();
if (in == EOF) return -1;
while (in != '-' && in != '.' && (in < '0' || in > '9')) in = _getchar();
if (in == '-') {
IsN = true;
x = 0;
} else if (in == '.') {
IsD = true;
x = 0;
} else
x = in - '0';
if (!IsD) {
while (in = _getchar(), in >= '0' && in <= '9') {
x *= 10;
x += in - '0';
}
}
if (in != '.') {
if (IsN) x = -x;
return 1;
} else {
while (in = _getchar(), in >= '0' && in <= '9') {
x += Dec * (in - '0');
Dec *= 0.1;
}
}
if (IsN) x = -x;
return 1;
}
inline int read(float &x) {
char in;
double Dec = 0.1;
bool IsN = false, IsD = false;
in = _getchar();
if (in == EOF) return -1;
while (in != '-' && in != '.' && (in < '0' || in > '9')) in = _getchar();
if (in == '-') {
IsN = true;
x = 0;
} else if (in == '.') {
IsD = true;
x = 0;
} else
x = in - '0';
if (!IsD) {
while (in = _getchar(), in >= '0' && in <= '9') {
x *= 10;
x += in - '0';
}
}
if (in != '.') {
if (IsN) x = -x;
return 1;
} else {
while (in = _getchar(), in >= '0' && in <= '9') {
x += Dec * (in - '0');
Dec *= 0.1;
}
}
if (IsN) x = -x;
return 1;
}
inline int read(char *x) {
char *tmp = x;
char in = _getchar();
while (in <= ' ' && in != EOF) in = _getchar();
if (in == -1) return -1;
while (in > ' ') *(tmp++) = in, in = _getchar();
*tmp = '\0';
return 1;
}
void Gao1(int, int, int);
void Gao2(int, int, int);
void Gao3(int, int, int);
void Gao1(int i, int a, int b) {
if (i == -1) {
printf("! %d %d\n", a, b);
fflush(stdout);
exit(0);
}
int x, y;
printf("? %d %d\n", a, b ^ (1 << i));
fflush(stdout);
scanf("%d", &x);
if (x == 0) Gao2(i - 1, a, b ^ (1 << i));
if (x == 1) {
int x;
printf("? %d %d\n", a ^ (1 << i), b ^ (1 << i));
fflush(stdout);
scanf("%d", &x);
if (x == 1)
Gao3(i - 1, a, b ^ (1 << i));
else
Gao1(i - 1, a ^ (1 << i), b ^ (1 << i));
}
if (x == -1) {
int x;
printf("? %d %d\n", a ^ (1 << i), b);
fflush(stdout);
scanf("%d", &x);
if (x == 0) Gao2(i - 1, a, b ^ (1 << i));
if (x == 1) Gao1(i - 1, a, b);
if (x == -1) Gao1(i - 1, a, b ^ (1 << i));
}
}
void Gao2(int i, int a, int b) {
if (i == -1) {
printf("! %d %d\n", a, b);
fflush(stdout);
exit(0);
}
a ^= 1 << i;
printf("? %d %d\n", a, b);
fflush(stdout);
int x;
scanf("%d", &x);
if (x == -1)
Gao2(i - 1, a, b ^ (1 << i));
else
Gao2(i - 1, a ^ (1 << i), b);
}
void Gao3(int i, int a, int b) {
if (i == -1) {
printf("! %d %d\n", a, b);
fflush(stdout);
exit(0);
}
int x, y;
printf("? %d %d\n", a ^ (1 << i), b);
fflush(stdout);
scanf("%d", &x);
if (x == 0) Gao2(i - 1, a ^ (1 << i), b);
if (x == -1) {
int x;
printf("? %d %d\n", a ^ (1 << i), b ^ (1 << i));
fflush(stdout);
scanf("%d", &x);
if (x == -1)
Gao1(i - 1, a ^ (1 << i), b);
else
Gao3(i - 1, a ^ (1 << i), b ^ (1 << i));
}
if (x == 1) {
int x;
printf("? %d %d\n", a, b ^ (1 << i));
fflush(stdout);
scanf("%d", &x);
if (x == -1) Gao3(i - 1, a, b);
if (x == 1) Gao3(i - 1, a ^ (1 << i), b);
}
}
int main() {
printf("? %d %d\n", 0, 0);
fflush(stdout);
int x;
scanf("%d", &x);
if (x == -1) Gao1(29, 0, 0);
if (x == 0) Gao2(29, 0, 0);
if (x == 1) Gao3(29, 0, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[35], b[35], diff[35];
int main() {
std::ios::sync_with_stdio(false);
int t;
t = 1;
while (t--) {
long long x, x1, val, val1, i, j, res = 0;
cout << "? 0 0" << endl;
cin >> x;
x1 = x;
if (x == 0) {
for (i = 0; i < 30; i++) {
val = (1 << i);
cout << "? " << val << " " << 0 << endl;
cin >> x;
if (x == -1) {
res += (1 << i);
}
}
cout << "! " << res << " " << res << endl;
} else {
{
x1 = x;
i = 29;
val = 0;
val1 = 0;
for (i = 29; i >= 0; i--) {
val += (1 << i);
val1 += (1 << i);
cout << "? " << val << " " << val1 << endl;
cin >> x;
if (x != x1) {
diff[i] = 1;
val -= (1 << i);
if (x == -1) {
a[i] = 1;
b[i] = 0;
} else {
a[i] = 0;
b[i] = 1;
}
cout << "? " << val << " " << val1 << endl;
cin >> x;
x1 = x;
} else {
diff[i] = 0;
}
}
for (i = 29; i >= 0; i--) {
val = 0;
val1 = 0;
if (diff[i]) {
continue;
}
for (j = 0; j < 30; j++) {
if (j == i) {
continue;
}
if (diff[j]) {
val += (1 << j);
}
}
{
val += (1 << i);
cout << "? " << val << " " << val1 << endl;
cin >> x;
if (x == -1) {
a[i] = 1;
b[i] = 1;
} else {
a[i] = 0;
b[i] = 0;
}
}
}
val = 0;
val1 = 0;
for (i = 0; i < 30; i++) {
if (a[i]) {
val += (1 << i);
}
if (b[i]) {
val1 += (1 << i);
}
}
cout << "! " << val << " " << val1 << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int ask(int c, int d) {
printf("? %d %d\n", c, d);
fflush(stdout);
int lins;
scanf("%d", &lins);
return lins;
}
int main() {
int a = 0, b = 0;
int cmp = ask(a, b);
for (int i = 29; i >= 0; i--) {
int cal_a = ask(a ^ (1 << i), b);
int cal_b = ask(a, b ^ (1 << i));
if (cal_a == cal_b) {
if (cmp == 1) {
a ^= (1 << i);
} else {
b ^= (1 << i);
}
cmp = cal_a;
} else if (cal_b == 1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int a = 0;
int b = 0;
int bit = 1 << 29;
int ans = 0;
cout << "? " << 0 << " " << 0 << endl;
cout.flush();
int cstate;
cin >> cstate;
for (int i = 0; i < 30; i++) {
if (cstate != 0) {
cout << "? " << a + bit << " " << b + bit << endl;
cout.flush();
cin >> ans;
if (ans == cstate) {
cout << "? " << a + bit << " " << b << endl;
cout.flush();
cin >> ans;
if (ans == -1) {
a += bit;
b += bit;
}
} else {
if (cstate == 1) {
a += bit;
} else {
b += bit;
}
cout << "? " << a << " " << b << endl;
cout.flush();
cin >> cstate;
}
} else {
cout << "? " << a + bit << " " << b << endl;
cout.flush();
cin >> ans;
if (ans == -1) {
a += bit;
b += bit;
}
}
bit >>= 1;
}
cout << "! " << a << " " << b << endl;
cout.flush();
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const double dinf = 1e250;
const long long INF = static_cast<long long>(2e18);
const int inf = static_cast<int>(1e9 + 7);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
void OUT(T a) {
cout << a;
exit(0);
}
template <typename T>
inline bool amax(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template <typename T>
inline bool amin(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
mt19937 rng(static_cast<uint32_t>(
chrono::steady_clock::now().time_since_epoch().count()));
chrono::time_point<chrono::steady_clock> cl;
double current_time() {
return (chrono::steady_clock::now() - cl).count() / 1e9;
}
int c = 0;
int d = 0;
int bit;
int cur;
int go(int cc, int dd) {
int resp;
cout << "? " << c + (cc << bit) << " " << d + (dd << bit) << endl;
cin >> resp;
return resp;
}
void ch(int cc, int dd) {
c += (cc << bit);
d += (dd << bit);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(10);
cl = chrono::steady_clock::now();
cin.tie(0);
int ord = go(0, 0);
for (bit = 29; bit >= 0; --bit) {
cur = go(1, 1);
if (cur == 0) {
int tmp = go(1, 0);
if (tmp == -1) ch(1, 1);
if (tmp == 1) ch(0, 0);
} else if (ord == cur) {
if (ord == 1) cur = go(0, 1);
if (ord == -1) cur = go(1, 0);
if (cur == ord) ch(1, 1);
} else {
if (ord == -1)
ord = go(1, 0), ch(0, 1);
else if (ord == 1)
ord = go(0, 1), ch(1, 0);
}
}
cout << "! " << c << " " << d;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
return l > r ? l = r, 1 : 0;
}
bool rev = false;
long long C, D;
bool same = false;
long long query(long long a, long long b) {
if (rev) swap(a, b);
cout << "? " << a + C << " " << b + D << endl;
long long x;
cin >> x;
if (rev) x *= -1;
if (x == 0) same = true;
return x;
}
void add(long long a, long long b) {
if (rev) swap(a, b);
C += a;
D += b;
}
signed main() {
if (query(0, 0) == -1) rev = true;
for (int i = int(30) - 1; i >= (0); --i) {
if (same) {
rev = false;
if (query(1 << i, 0) == 1)
;
else
add(1 << i, 1 << i);
continue;
}
long long ans = query(1 << i, 1 << i);
if (ans == 0) {
i--;
same = true;
continue;
}
if (ans == 1) {
ans = query(1 << i, 0);
if (ans == 1) {
} else if (ans == 0) {
} else {
add(1 << i, 1 << i);
}
} else {
add(1 << i, 0);
if (query(0, 0) == -1) rev ^= true;
}
}
cout << "! " << C << " " << D << endl;
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 1e2 + 2;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
int a[2], o, f, s, p;
int main() {
ios_base::sync_with_stdio(0);
cout << "? 0 0" << endl;
cin >> o;
if (o == 0) o = 1;
if (o == -1) p = 1;
for (int i = 29; i >= 0; i--) {
a[p] += (1 << i);
cout << "? " << a[0] << " " << a[1] << endl;
cin >> f;
a[p] -= (1 << i);
cout << "? " << a[0] + (1 << i) << " " << a[1] + (1 << i) << endl;
cin >> s;
if (f == 0) a[p] += (1 << i);
if (f == o && s == -o) a[p] += (1 << i);
if (f == -o && s == 0) a[0] += (1 << i), a[1] += (1 << i);
if (f == -o && s == o) a[0] += (1 << i), a[1] += (1 << i);
if (f == -o && s == -o) a[p] += (1 << i), p = (1 - p), o = -o;
}
cout << "! " << a[0] << " " << a[1] << endl;
}
|
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int maxn = 2e4 + 10;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const double eps = 1e-7;
using namespace std;
int a[50], b[50], ans1, ans2, pre, lastt;
int main() {
cout << "? " << 0 << " " << 0 << endl;
scanf("%d", &lastt);
pre = 0;
for (int i = 29; i >= 0; --i) {
int op1, op2, tmp = 1 << i;
cout << "? " << pre + tmp << " " << 0 << endl;
scanf("%d", &op1);
cout << "? " << pre << " " << tmp << endl;
scanf("%d", &op2);
if (op1 != op2) {
if (op1 == -1)
a[i] = 1, b[i] = 1;
else
a[i] = 0, b[i] = 0;
} else {
if (lastt == 1)
a[i] = 1, b[i] = 0;
else
a[i] = 0, b[i] = 1;
lastt = op1;
pre += tmp;
}
}
for (int i = 29; i >= 0; --i) {
ans1 += a[i] * (1 << i);
ans2 += b[i] * (1 << i);
}
printf("! %d %d\n", ans1, ans2);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
cout << "? " << c << ' ' << d << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
int a = 0, b = 0, big = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
if (f == s) {
if (big == 1)
a ^= (1 << i);
else
b ^= (1 << i);
big = f;
} else if (f == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << ' ' << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int a = 0, b = 0, flag;
int ask(int x, int y) {
cout << "? " << x << ' ' << y << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
flag = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int t = ask(a ^ (1 << i), b), tt = ask(a, b ^ (1 << i));
if (t == tt) {
if (flag == 1)
a ^= (1 << i);
else if (flag == -1)
b ^= (1 << i);
flag = t;
} else if (t == -1)
a ^= (1 << i), b ^= (1 << i);
}
cout << "! " << a << ' ' << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, k, i;
int ans1 = 0, ans2 = 0, a = 0, b = 0;
cout << "? " << ans1 << " " << ans2 << endl;
cin >> k;
for (i = 29; i >= 0; i--) {
int op1 = ans1 + (1 << i);
int op2 = ans2 + (1 << i);
cout << "? " << op1 << " " << op2 << endl;
cin >> j;
if (j != k) {
if (j == 1)
b = b + (1 << i), ans2 = ans2 + (1 << i);
else
a = a + (1 << i), ans1 = ans1 + (1 << i);
cout << "? " << ans1 << " " << ans2 << endl;
cin >> k;
} else {
op1 = ans1 + (1 << i);
op2 = ans2;
cout << "? " << op1 << " " << op2 << endl;
cin >> j;
if (j == -1) a = a + (1 << i), b = b + (1 << i);
}
}
cout << "! " << a << " " << b << '\n';
return 0;
}
|
#include <bits/stdc++.h>
int Q(int x, int y) {
printf("? %d %d\n", x, y);
fflush(stdout);
std::cin >> x;
return x;
}
int32_t main() {
int a = 0, b = 0, t = Q(0, 0), x, y, i = 1 << 30;
while (i >>= 1) {
x = Q(a | i, b);
y = Q(a, b | i);
if (x == y) {
if (t > 0)
a |= i;
else
b |= i;
t = x;
} else if (x == -1) {
a |= i, b |= i;
}
}
printf("! %d %d\n", a, b);
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long query(long long c, long long d) {
long long re;
cout << "? " << c << " " << d << "\n", fflush(stdout);
cin >> re;
return re;
}
const long long C = 29;
int main() {
long long a = 0, b = 0, x, y, z, type;
x = query(1LL << C, 0), y = query(0, 1LL << C);
if (x == 1)
if (y == 1) {
z = query(0, 0), type = 1;
if (z == 1)
a = 1LL << C;
else
b = 1LL << C;
} else
type = query(0, 0);
else if (x == -1)
if (y == -1) {
z = query(0, 0), type = -1;
if (z == 1)
a = 1LL << C;
else
b = 1LL << C;
} else
a = b = 1LL << C, type = query(0, 0);
else if (type = 0, y == -1)
a = b = 1LL << C;
else if (y == 0) {
z = query(0, 0);
if (z == 1)
a = 1LL << C;
else
b = 1LL << C;
}
for (long long i = 1LL << (C - 1); i; i >>= 1) {
x = query(a | i, b);
y = query(a, b | i);
if (x == 1)
if (y == 1) {
z = type, type = 1;
if (z == 1)
a |= i;
else
b |= i;
} else
;
else if (x == -1)
if (y == -1) {
z = type, type = -1;
if (z == 1)
a |= i;
else
b |= i;
} else
a |= i, b |= i;
else if (y == -1)
a |= i, b |= i, type = 0;
else if (y == 0) {
z = type, type = 0;
if (z == 1)
a |= i;
else
b |= i;
} else
type = 0;
}
cout << "! " << a << ' ' << b << "\n", fflush(stdout);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(NULL));
int _a = abs(rand());
int bger[30] = {
0,
};
int A = 0, B = 0;
bool flag = false;
int a;
for (int i = 29; i >= 0; i--) {
if (flag) {
cout << "? " << (A ^ (1 << i)) << " " << B << endl;
fflush(stdout);
cin >> a;
if (a == -1) {
A ^= (1 << i);
B ^= (1 << i);
}
continue;
}
if (bger[i] == 0) {
cout << "? " << A << " " << B << endl;
fflush(stdout);
cin >> a;
if (a == 0) {
flag = true;
i++;
continue;
}
bger[i] = a;
}
cout << "? " << (A ^ (1 << i)) << " " << (B ^ (1 << i)) << endl;
fflush(stdout);
cin >> a;
if (a == bger[i]) {
bger[i - 1] = bger[i];
cout << "? " << (A ^ (1 << i)) << " " << B << endl;
fflush(stdout);
cin >> a;
if (a == -1) {
A ^= (1 << i);
B ^= (1 << i);
}
} else {
if (bger[i] == 1)
A ^= (1 << i);
else
B ^= (1 << i);
}
}
cout << "! " << A << " " << B << endl;
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, j, ans, sum, A[40], B[40], C[40], x[40], u, point, k,
u1, fix[40], ind1 = 30, ww, ww1;
bool ok = true;
void point1(long long p, long long AA, long long BB, long long K) {
ind1--;
if (ind1 == -1) ok = false;
if (ind1 >= 0) {
if (p == 1) {
for (int i1 = ind1; i1 >= 0; i1--) {
if (ok) {
cout << "? " << x[i1] + AA << " " << x[i1] + BB << endl;
cin >> u;
if (u == 0) {
ok = false;
return;
}
if (u != 1) {
if (u == -1) {
cout << "? " << x[i1] + AA << " " << BB << endl;
cin >> u;
if (u == 1 && ok) {
A[ind1] = 1;
fix[ind1] = 1;
point1(1, AA + x[i1], BB, 0);
} else {
A[ind1] = 1;
fix[ind1] = 1;
point1(-1, AA + x[i1], BB, 0);
}
}
} else {
point1(1, AA, BB, K + 1);
}
} else
return;
}
} else {
for (int i1 = ind1; i1 >= 0; i1--) {
if (ok) {
cout << "? " << x[i1] + AA << " " << x[i1] + BB << endl;
cin >> u;
if (u == 0) {
ok = false;
return;
}
if (u != -1) {
cout << "? " << AA << " " << BB + x[i1] << endl;
cin >> u;
if (u == -1 && ok) {
B[ind1] = 1;
fix[ind1] = 1;
point1(-1, AA, BB + x[i1], 0);
} else {
B[ind1] = 1;
fix[ind1] = 1;
point1(1, AA, BB + x[i1], 0);
}
} else {
point1(-1, AA, BB, K + 1);
}
} else
return;
}
}
}
return;
}
int main() {
x[0] = 1;
for (int i = 1; i <= 33; i++) {
x[i] = x[i - 1] * 2;
}
c = 0;
cout << "? " << c << " " << c << endl;
cin >> point;
if (point == 0) {
c = 0;
d = 0;
for (i = 29; i >= 0; i--) {
c = x[i];
cout << "? " << c << " " << 0 << endl;
cin >> u;
if (u == -1) A[i] = 1;
}
c = 0;
for (i = 29; i >= 0; i--)
if (A[i]) c += x[i];
cout << "! " << c << " " << c << endl;
return 0;
}
if (point != 0) {
if (point == 1)
point1(1, 0, 0, 1);
else
point1(-1, 0, 0, 1);
a = b = 0;
for (i = 32; i >= 0; i--)
if (A[i]) a += x[i];
for (i = 32; i >= 0; i--)
if (B[i]) b += x[i];
for (i = 29; i >= 0; i--) {
if (fix[i] == 0) {
ww = (x[i] + a);
ww1 = (0 + b);
cout << "? " << ww << " " << ww1 << endl;
cin >> u;
if (u == -1) A[i] = B[i] = 1;
}
}
a = b = 0;
for (i = 32; i >= 0; i--)
if (A[i]) a += x[i];
for (i = 32; i >= 0; i--)
if (B[i]) b += x[i];
cout << "! " << a << " " << b << endl;
for (i = 0; i <= 5; i++) {
cout << A[i] << " ";
}
cout << endl;
for (i = 0; i <= 5; i++) {
cout << B[i] << " ";
}
cout << endl;
return 0;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 5;
const int inf = 1e9;
int ask(int c, int d) {
cout << "? " << c << " " << d << endl;
int x;
cin >> x;
return x;
}
int main() {
int v[2] = {};
int cur;
int tm = ask(0, 0);
bool eq = false;
if (tm == 1)
cur = 0;
else if (tm == 0)
eq = true;
else
cur = 1;
map<pair<int, int>, pair<int, int> > mp;
mp[{0, 0}] = {1, 0};
mp[{1, 1}] = {1, 0};
mp[{1, -1}] = {0, 0};
mp[{-1, 1}] = {1, 1};
mp[{-1, -1}] = {1, 0};
for (int i = 29; i >= 0; i--) {
if (eq) {
int t = ask(v[0] | (1 << i), v[1]);
if (t == -1) {
v[0] |= 1 << i;
v[1] |= 1 << i;
}
continue;
}
int x = ask(v[0] | (1 << i), v[1]);
int y = ask(v[0], v[1] | (1 << i));
pair<int, int> z = mp[{x, y}];
if (cur == 0) {
if (z.first == 1) v[0] |= 1 << i;
if (z.second == 1) v[1] |= 1 << i;
if ((z == make_pair(0, 0)) || (z == make_pair(1, 1))) continue;
if (x == -1) cur = 1;
} else {
if (z.first == 1) v[1] |= 1 << i;
if (z.second == 1) v[0] |= 1 << i;
if ((z == make_pair(0, 0)) || (z == make_pair(1, 1))) continue;
if (y == 1) cur = 0;
}
}
cout << "! " << v[0] << " " << v[1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
cout << "[";
for (int i = 0; i < v.size(); i++) {
if (i) cout << ", ";
cout << v[i];
}
return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
long long n, m, k, q, Q, T, l, r, x, y, z;
long long c[1000005];
string second, t;
long long ans = 0;
int pt, a, b;
int query(int a, int b) {
cout << "? " << a << " " << b << endl;
cin >> x;
return x;
}
void getZero() {
if (pt < 0) {
cout << "! " << a << " " << b << endl;
exit(0);
}
b ^= (1 << pt);
x = query(a, b);
if (x == 1)
a ^= (1 << pt);
else
b ^= (1 << pt);
--pt;
getZero();
}
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
};
pt = 29;
a = b = 0;
int cache = -2;
while (pt >= 0) {
int x, y;
if (cache == -2) {
x = query(a, b);
} else
x = cache;
if (x == 0) getZero();
a ^= (1 << pt);
b ^= (1 << pt);
y = query(a, b);
if (x == y)
cache = x;
else
cache = -2;
if (x == y) {
a ^= (1 << pt);
z = query(a, b);
if (z == 1)
a ^= (1 << pt);
else
b ^= (1 << pt);
} else {
if (x > y)
b ^= (1 << pt);
else
a ^= (1 << pt);
}
--pt;
}
cout << "! " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
bool fl;
int a, b;
int ask(int x, int y) {
printf("? %d %d\n", x, y);
fflush(stdout);
int res = 0;
scanf("%d", &res);
return res;
}
int main() {
a = b = 0;
fl = 1;
if (ask(a, b) < 0) fl = 0;
for (int i = 29; i >= 0; i--) {
int qa = a ^ (1 << i), qb = b ^ (1 << i);
int x = ask(qa, b), y = ask(a, qb);
if (x == y) {
if (fl)
a ^= (1 << i);
else
b ^= (1 << i);
fl = (x == 1);
} else if (x == -1 && y == 1)
a ^= (1 << i), b ^= (1 << i);
}
printf("! %d %d\n", a, b);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 ran(seed);
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
clock_t start = clock();
int gcd(int a, int b) { return (a == 0) ? b : gcd(b % a, a); }
int power(int a, int n) {
int p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
int powm(int a, int n, int mod_) {
int p = 1;
while (n) {
if (n % 2) {
p = (((p % mod_) * 1LL * (a % mod_)) % mod_);
}
n >>= 1;
a = (((a % mod_) * 1LL * (a % mod_)) % mod_);
}
return p % mod_;
}
int powi(int a, int mod_) { return powm(a, mod_ - 2, mod_); }
map<pair<int, int>, int> dp;
int ask(int x, int y) {
if (dp.count({x, y})) return dp[{x, y}];
cout << "? " << x << " " << y << endl;
int a;
cin >> a;
if (a == -2) exit(0);
return dp[{x, y}] = a;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int mn, mx;
int n, m, k, t, i, j, sum = 0, flag = 0, cnt = 0;
int x = 0, y = 0, z, l = 0, r = 0, q;
int TC = 1;
while (TC--) {
x = y = 0;
for (i = (1 << 29); i > 0; i >>= 1) {
l = ask(x, y);
r = ask(x + i, y + i);
if (l == r) {
l = ask(x + i, y);
if (l == -1) {
dp[{x + i, y + i}] = dp[{x, y}];
x += i;
y += i;
}
continue;
}
if (r == -1)
x += i;
else if (r == 1)
y += i;
}
cout << "! " << x << " " << y << endl;
};
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int read() {
int res = 0;
char ch = 0;
bool f = false;
do f = ch == 45;
while (!isdigit(ch = getchar()));
for (; isdigit(ch); ch = getchar()) (res *= 10) += ch - 48;
return f ? -res : res;
}
using IPair = array<int, 2>;
bool operator<(const IPair& lhs, const IPair& rhs) {
return lhs[0] * rhs[1] == rhs[0] * lhs[1] ? lhs[1] < rhs[1]
: lhs[0] * rhs[1] < rhs[0] * lhs[1];
}
const int maxN = 300010;
vector<int> G[maxN];
IPair dp[maxN][2];
int w[maxN];
int n;
void dfs(int u, int from) {
dp[u][0] = {INT_MIN, 0};
dp[u][1] = {w[u], 1};
for (const int v : G[u]) {
if (v == from) continue;
dfs(v, u);
IPair t1 = {dp[v][0][0] + w[u], dp[v][0][1] + 1};
IPair t2 = {dp[v][1][0] + dp[u][1][0], dp[v][1][1]};
IPair t3 = {dp[v][1][0] + dp[u][1][0], dp[v][1][1] + 1};
if (dp[u][1] < t1) dp[u][1] = t1;
if (dp[u][1] < t2) dp[u][1] = t2;
if (dp[u][1] < t3) dp[u][1] = t3;
if (dp[u][0] < dp[v][0]) dp[u][0] = dp[v][0];
if (dp[u][0] < dp[v][1]) dp[u][0] = dp[v][1];
}
}
int prea = 0, preb = 0;
int a[36];
void fun0(int t) {
for (int i = 0; i < t; i++) {
int tmp;
cout << "? " << prea + a[i] << " " << preb << endl << flush;
cin >> tmp;
if (tmp == -1) {
prea += a[i];
preb += a[i];
}
}
cout << "! " << prea << " " << preb << endl << flush;
}
int fun1(int x) {
int tmp;
cout << "? " << prea + a[x] << " " << preb + a[x] << endl << flush;
cin >> tmp;
if (tmp == 1) {
int tmp2;
cout << "? " << prea << " " << preb + a[x] << endl << flush;
cin >> tmp2;
if (tmp2 == 1) {
prea += a[x];
preb += a[x];
return 1;
}
if (tmp2 == -1) {
return 1;
}
}
if (tmp == -1) {
int tmp2;
prea += a[x];
cout << "? " << prea << " " << preb << endl << flush;
cin >> tmp2;
return tmp2;
}
}
int fun2(int x) {
int tmp;
cout << "? " << prea + a[x] << " " << preb + a[x] << endl << flush;
cin >> tmp;
if (tmp == -1) {
int tmp2;
cout << "? " << prea + a[x] << " " << preb << endl << flush;
cin >> tmp2;
if (tmp2 == -1) {
prea += a[x];
preb += a[x];
return -1;
}
if (tmp2 == 1) {
return -1;
}
}
if (tmp == 1) {
int tmp2;
preb += a[x];
cout << "? " << prea << " " << preb << endl << flush;
cin >> tmp2;
return tmp2;
}
}
signed main() {
a[0] = 1;
for (int i = 1; i < 30; i++) a[i] = a[i - 1] + a[i - 1];
int tmp;
cout << "? 0 0" << endl << flush;
cin >> tmp;
if (tmp == 0) {
fun0(30);
return 0;
} else {
for (int i = 29; i >= 0; i--) {
if (tmp == 0) {
fun0(i + 1);
return 0;
}
if (tmp == 1)
tmp = fun1(i);
else
tmp = fun2(i);
}
fun0(0);
}
return 0;
}
|
#include <bits/stdc++.h>
const int N = 32;
int n;
int c[N], d[N];
int toint(int x[]) {
int sum = 0;
for (int i = N - 1; i >= 0; --i) {
sum <<= 1;
sum += x[i];
}
return sum;
}
int ask(int x, int y) {
std::cout << "? " << x << " " << y << std::endl;
fflush(stdout);
int ans;
std::cin >> ans;
return ans;
}
int q[N][2];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
for (int i = 0; i < N; ++i)
for (int j = 0; j < 2; ++j) q[i][j] = -2;
for (int i = 29; i >= 0; --i) {
int ans0, ans1;
if (q[i][0] == -2) {
ans0 = ask(toint(c), toint(d));
} else {
ans0 = q[i][0];
}
c[i] = d[i] = 1;
ans1 = ask(toint(c), toint(d));
if (ans0 != ans1) {
if (ans0 == 1) {
c[i] = 1;
d[i] = 0;
} else {
c[i] = 0;
d[i] = 1;
}
} else {
if (i > 0) {
q[i - 1][0] = ans0;
}
c[i] = 1;
d[i] = 0;
int ans2 = ask(toint(c), toint(d));
if (ans2 == -1) {
c[i] = d[i] = 1;
} else {
c[i] = d[i] = 0;
}
}
}
std::cout << "! " << toint(c) << " " << toint(d) << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 40;
int verd, lastv;
int c, d;
bool defed[maxn];
int main() {
int ca = 0;
c = d = 0;
memset(defed, false, sizeof(defed));
while (true) {
if (ca == 0) {
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &verd);
lastv = verd;
} else {
for (int i = 29; i >= 0; --i) {
printf("? %d %d\n", c | (1 << i), d | (1 << i));
fflush(stdout);
scanf("%d", &verd);
if (lastv != verd) {
defed[i] = true;
if (lastv == 1) {
c |= 1 << i;
} else if (lastv == -1) {
d |= 1 << i;
} else {
printf("wtf\n");
}
printf("? %d %d\n", c, d);
fflush(stdout);
scanf("%d", &verd);
if (verd == 0) {
break;
}
lastv = verd;
}
}
for (int i = 0; i < 30; ++i) {
if (defed[i]) continue;
printf("? %d %d\n", c | (1 << i), d);
fflush(stdout);
scanf("%d", &verd);
if (verd == -1) {
c |= 1 << i;
d |= 1 << i;
}
}
break;
}
ca++;
}
printf("! %d %d\n", c, d);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int query(int x, int y) {
cout << "? " << x << " " << y << endl;
int p;
cin >> p;
return p;
}
inline void print(int x, int y) { cout << "! " << x << " " << y << endl; }
int num[30];
int main() {
int tmp, tmp2, sum1 = 0, sum2 = 0, a = 0, b = 0;
tmp = query(0, 0);
for (int i = 29; ~i; --i) {
sum1 |= (1 << i);
sum2 |= (1 << i);
tmp2 = query(sum1, sum2);
if (tmp2 != tmp && tmp2) {
num[i] = -tmp2;
sum1 ^= (1 << i);
tmp = query(sum1, sum2);
} else
num[i] = 0;
}
for (int i = 29; ~i; --i) {
if (num[i] == 1) a |= (1 << i);
if (num[i] == -1) b |= (1 << i);
if (!num[i]) {
tmp2 = query(sum1 ^ (1 << i), sum2);
if (tmp2 == 1) a |= (1 << i), b |= (1 << i);
}
}
print(a, b);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
long long c, d, f, curr, pre;
void equal() {
d -= (1 << curr);
cout << "? " << c << " " << d << endl;
cin >> f;
if (f > 0) c -= (1 << curr);
if (f < 0) d += (1 << curr);
pre = 0;
}
void ggreater() {
cout << "? " << c << " " << d << endl;
cin >> f;
if (f < 0) {
d -= (1 << curr);
cout << "? " << c << " " << d << endl;
cin >> pre;
} else {
c -= (1 << curr);
cout << "? " << c << " " << d << endl;
cin >> f;
pre = 1;
if (f > 0) c += (1 << curr);
if (f < 0) d -= (1 << curr);
}
}
void samaller() {
cout << "? " << c << " " << d << endl;
cin >> f;
if (f > 0) {
c -= (1 << curr);
cout << "? " << c << " " << d << endl;
cin >> pre;
} else {
d -= (1 << curr);
cout << "? " << c << " " << d << endl;
cin >> f;
pre = -1;
if (f < 0) d += (1 << curr);
if (f > 0) c -= (1 << curr);
}
}
void solve() {
curr = 29;
cout << "? " << c << " " << d << endl;
cin >> pre;
c = (1 << curr), d = (1 << curr);
while (curr >= 0) {
if (pre == 0)
equal();
else if (pre == 1)
ggreater();
else
samaller();
curr--;
if (curr >= 0) c += (1 << curr), d += (1 << curr);
}
cout << "! " << c << " " << d << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
start = clock();
cout << fixed << setprecision(15);
while (t--) {
solve();
}
double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC);
cerr << time_taken;
}
|
#include <bits/stdc++.h>
using namespace std;
const int B = 30;
int ask(int c, int d) {
printf("? %d %d\n", c, d);
fflush(stdout);
int resp;
scanf("%d", &resp);
if (resp == -2) exit(0);
return resp;
}
int main() {
int ma = 0, mb = 0, a = 0, b = 0;
int state = ask(0, 0);
for (int i = B - 1; i >= 0; i--) {
int bit = (1 << i);
if (state == 0) {
int resp = ask(ma ^ bit, mb);
if (resp == -1) {
a |= bit;
b |= bit;
}
} else {
int resp = ask(ma ^ bit, mb ^ bit);
if (resp != state) {
if (resp == 1) {
b |= bit;
mb |= bit;
} else {
a |= bit;
ma |= bit;
}
state = ask(ma, mb);
} else {
resp = ask(ma ^ bit, mb);
if (resp == -1) {
a |= bit;
b |= bit;
}
}
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, st, k1, k2, a = 0, b = 0;
cout << "?"
<< " " << a << " " << b << endl;
cin >> st;
for (int i = 29; i >= 0; i--) {
cout << "?"
<< " " << int(a | (1 << i)) << " " << b << endl;
cin >> k1;
cout << "?"
<< " " << b << " " << int(a | (1 << i)) << endl;
cin >> k2;
if (k1 == -1 && k2 == 1)
a |= (1 << i), b |= (1 << i);
else if (k1 == k2) {
if (st == 1)
a |= (1 << i);
else
b |= (1 << i);
st = k1;
}
}
cout << "!"
<< " " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string debug(long long x) {
if (x == 0) cout << 0;
stack<int> q;
while (x != 0) {
q.push(x % 2);
x /= 2;
}
while (!q.empty()) {
cout << q.top();
q.pop();
}
return "";
}
int cmp(int x, int y) {
if (x > y) return 1;
if (x < y) return -1;
return 0;
}
int main() {
int ans, ans1, ans2;
cout << "? 0 0" << endl;
fflush(stdout);
cin >> ans;
long long r1 = 0, r2 = 0;
long long tmp1, tmp2;
for (int i = 29; i >= 0; --i) {
if (ans == 0) ans = 1;
tmp1 = r1, tmp2 = r2;
tmp1 |= (1 << i);
tmp2 |= (1 << i);
cout << "? " << r1 << " " << tmp2 << endl;
fflush(stdout);
cin >> ans1;
cout << "? " << tmp1 << " " << r2 << endl;
fflush(stdout);
cin >> ans2;
if (ans1 == 0) ans1 = 1;
if (ans2 == 0) ans2 = 1;
if (ans == 1) {
if (ans1 == 1 && ans2 == -1) {
r1 |= (1 << i);
r2 |= (1 << i);
ans = 1;
}
if (ans1 == -1 && ans2 == 1) {
ans = 1;
}
if (ans1 == 1 && ans2 == 1) {
r1 |= (1 << i);
ans = 1;
}
if (ans1 == -1 && ans2 == -1) {
r1 |= (1 << i);
ans = -1;
}
} else {
if (ans1 == 1 && ans2 == -1) {
r1 |= (1 << i);
r2 |= (1 << i);
ans = -1;
}
if (ans1 == -1 && ans2 == 1) {
ans = -1;
}
if (ans1 == -1 && ans2 == -1) {
r2 |= (1 << i);
ans = -1;
}
if (ans1 == 1 && ans2 == 1) {
r2 |= (1 << i);
ans = 1;
}
}
}
cout << "! " << r1 << " " << r2 << endl;
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
int a, b;
void parham(int guess_num, int ar[30], int br[30], int *pmax);
int power_2(int n);
int main() {
int max = 0, i, ar[30], br[30];
parham(1, ar, br, &max);
for (i = 2; i <= 62; i += 2) parham(i, ar, br, &max);
return 0;
}
int power_2(int n) {
if (n == 0)
return 1;
else if (n >= 1)
return 2 * power_2(n - 1);
}
void parham(int guess_num, int ar[30], int br[30], int *pmax) {
int iman1, iman2;
if (guess_num == 1) {
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &iman1);
if (iman1 == 1)
*pmax = 1;
else if (iman1 == -1)
*pmax = -1;
else
*pmax = 0;
} else if (guess_num >= 2 && guess_num <= 61) {
printf("? %d %d\n", a, power_2(30 - (guess_num / 2)) + b);
fflush(stdout);
scanf("%d", &iman1);
printf("? %d %d\n", power_2(30 - (guess_num / 2)) + a, b);
fflush(stdout);
scanf("%d", &iman2);
if (iman1 == 1 && iman2 == -1) {
ar[30 - (guess_num / 2)] = 1;
br[30 - (guess_num / 2)] = 1;
a += power_2(30 - (guess_num / 2));
b += power_2(30 - (guess_num / 2));
} else if (iman1 == -1 && iman2 == 1) {
ar[30 - (guess_num / 2)] = 0;
br[30 - (guess_num / 2)] = 0;
} else {
if (*pmax == 1) {
ar[30 - (guess_num / 2)] = 1;
br[30 - (guess_num / 2)] = 0;
*pmax = iman1;
a += power_2(30 - (guess_num / 2));
} else if (*pmax == -1) {
ar[30 - (guess_num / 2)] = 0;
br[30 - (guess_num / 2)] = 1;
*pmax = iman1;
b += power_2(30 - (guess_num / 2));
}
}
} else if (guess_num == 62) {
int i, ans_a = 0, ans_b = 0;
for (i = 0; i <= 29; i++) {
ans_a += power_2(i) * ar[i];
ans_b += power_2(i) * br[i];
}
printf("! %d %d", ans_a, ans_b);
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long ask(long long c, long long d) {
cout << '?' << ' ' << c << ' ' << d << endl;
cout.flush();
long long ans;
cin >> ans;
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long a = 0, b = 0;
long long ans = ask(0, 0);
bool flag;
if (ans == 1)
flag = true;
else
flag = false;
for (long long i = 30 - 1; i >= 0; i--) {
long long ans1 = ask(a + (1 << i), b);
long long ans2 = ask(a, b + (1 << i));
if (ans1 == 1 && ans2 == -1) {
continue;
} else if (ans1 == -1 && ans2 == 1) {
a += (1 << i);
b += (1 << i);
} else if (flag) {
a += (1 << i);
if (ans1 == 1)
flag = true;
else
flag = false;
} else {
b += (1 << i);
if (ans1 == 1)
flag = true;
else
flag = false;
}
}
cout << '!' << ' ' << a << ' ' << b << endl;
cout.flush();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b;
int check(int c, int d) {
cout << "? " << c << " " << d << endl;
fflush(stdout);
int x;
cin >> x;
return x;
}
int main() {
int x1, x2, x3, x4, prevz;
int curP = (1 << 29);
x1 = check(a | curP, b);
x2 = check(a, b);
x3 = check(a | curP, b | curP);
x4 = check(a, b | curP);
if (x2 == x3) {
if (x1 == 1) {
a = a;
b = b;
prevz = x2;
} else if (x4 == 1) {
a = a | curP;
b = b | curP;
prevz = x3;
}
} else if (x2 == 1 && x3 == -1) {
a = a | curP;
b = b;
prevz = x1;
} else {
a = a;
b = b | curP;
prevz = x4;
}
for (int i = 28; i >= 0; i--) {
curP = (1 << i);
if (prevz == 1) {
x3 = check(a | curP, b | curP);
if (x3 == 1) {
x1 = check(a | curP, b);
if (x1 == 1) {
a = a;
b = b;
prevz = prevz;
} else {
a = a | curP;
b = b | curP;
prevz = x3;
}
} else {
a = a | curP;
b = b;
prevz = check(a, b);
}
} else if (prevz == 0) {
x1 = check(a | curP, b);
if (x1 == 1) {
a = a;
b = b;
prevz = check(a, b);
} else {
a = a | curP;
b = b | curP;
prevz = check(a, b);
}
} else {
x3 = check(a | curP, b | curP);
if (x3 == 1) {
a = a;
b = b | curP;
prevz = check(a, b);
} else {
x1 = check(a | curP, b);
if (x1 == 1) {
a = a;
b = b;
prevz = prevz;
} else {
a = a | curP;
b = b | curP;
prevz = x3;
}
}
}
}
cout << "! " << a << " " << b << endl;
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
int x;
printf("? %d %d\n", c, d);
fflush(stdout);
scanf("%d", &x);
return x;
}
int main() {
int a = 0, b = 0, f;
int c = 0, d = 0, h = 0, k = 0;
f = ask(c, d);
for (int i = 29; i >= 0; i--) {
if (f == 0) {
c = (1 << i), d = (0 << i);
if (ask(h | c, k | d) == -1) a |= 1 << i, b |= 1 << i;
continue;
}
c = (1 << i), d = (1 << i);
if (ask(a | c, b | d) == f) {
if (f == 1 && ask(a | c, b) == -f) {
a |= 1 << i;
b |= 1 << i;
}
if (f == -1 && ask(a, b | d) == -f) {
a |= 1 << i;
b |= 1 << i;
}
} else {
if (f == 1)
a |= 1 << i;
else
b |= 1 << i;
f = ask(a, b);
if (f == 0) h = a, k = b;
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int x, y;
set<int> s1;
int getResponse(int a, int b) {
int temp;
cout << "? " << a << " " << b << endl;
fflush(stdout);
cin >> temp;
return temp;
}
void getEqual(int a, int b) {
for (int i = 0; i < 30; i++) {
if (s1.find(i) == s1.end()) {
s1.insert(i);
if (getResponse(a ^ (1 << i), (b)) == -1) {
x ^= (1 << i);
y ^= (1 << i);
}
}
}
}
void getGreater(int a, int b, int resp, int bit) {
if (bit < 0) {
getEqual(a, b);
} else if (resp == 1) {
resp = getResponse(a ^ (1 << bit), b ^ (1 << bit));
if (resp == 1) {
getGreater(a, b, resp, bit - 1);
} else {
x ^= 1 << bit;
s1.insert(bit);
resp = getResponse(a ^ (1 << bit), b);
getGreater(a ^ (1 << bit), b, resp, bit - 1);
}
} else if (resp == -1) {
resp = getResponse(a ^ (1 << bit), b ^ (1 << bit));
if (resp == -1) {
getGreater(a, b, resp, bit - 1);
} else {
y ^= 1 << bit;
s1.insert(bit);
resp = getResponse(a ^ (1 << bit), b);
getGreater(a, b ^ (1 << bit), resp, bit - 1);
}
} else if (resp == 0) {
getEqual(a, b);
}
}
int main() {
int resp;
resp = getResponse(0, 0);
int a = 0, b = 0;
x = 0;
y = 0;
if (resp == 0) {
getEqual(a, b);
cout << "! " << x << " " << y << endl;
fflush(stdout);
} else {
getGreater(a, b, resp, 29);
cout << "! " << x << " " << y << endl;
fflush(stdout);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MAXM = 5e6 + 5;
const double eps = 1e-10;
const long long MOD = 998244353;
int x, y;
int cnt;
int judger(int c, int d) {
int aa = x ^ c, bb = y ^ d;
if (aa < bb)
return -1;
else if (aa == bb)
return 0;
else
return 1;
}
int read() {
int x;
cin >> x;
if (x == -2) {
exit(0);
}
return x;
}
void q(int c, int d) {
cout << "? " << c << " " << d << endl;
fflush(stdout);
}
int push(int c, int d) {
++cnt;
if (cnt == 63) {
puts("WA");
exit(0);
}
q(c, d);
int res = read();
return res;
}
int a[70];
int b[70];
int r1[70], r2[70], r3[70], r4[70];
int main() {
x = 3;
y = 1;
int la = push(0, 0), pre = 0;
for (int i = 29; i >= 0; --i) {
int x1 = 1 << i;
int r1 = push(pre + x1, 0);
int r2 = push(pre, x1);
int res;
if (r1 != r2) {
res = 0;
if (r1 == -1) {
a[i] = b[i] = 1;
} else
a[i] = b[i] = 0;
} else {
if (la == 1) {
a[i] = 1;
b[i] = 0;
} else {
a[i] = 0;
b[i] = 1;
}
la = r1;
pre += x1;
}
}
int a1 = 0, b1 = 0;
for (int i = 29; i >= 0; --i) {
a1 = (a1 << 1) + a[i];
b1 = (b1 << 1) + b[i];
}
printf("! %d %d\n", a1, b1);
if (a1 != x || b1 != y) {
printf("WA\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int aa = 12345677;
int bb = 789012;
int ask(int c, int d) {
if (0) {
if ((aa ^ c) > (bb ^ d)) return 1;
if ((aa ^ c) == (bb ^ d)) return 0;
if ((aa ^ c) < (bb ^ d)) return -1;
}
int res;
cout << "? " << c << ' ' << d << endl;
cout.flush();
cin >> res;
return res;
}
int a, b, r1, r2, r3;
int res[30];
int main() {
fill(res, res + 30, -1000);
for (int bit = 29; bit >= 0; bit--) {
if (res[bit] != -1000) {
r1 = res[bit];
} else {
r1 = ask(a, b);
}
if (r1 == 0) {
for (int i = bit; i >= 0; i--) res[i] = 0;
r3 = ask((a | (1 << bit)), b);
if (r3 == 1) {
} else {
a |= (1 << bit);
b |= (1 << bit);
}
} else {
r2 = ask((a | (1 << bit)), (b | (1 << bit)));
if (r1 == r2) {
r3 = ask((a | (1 << bit)), b);
if (r3 == 1) {
} else {
a |= (1 << bit);
b |= (1 << bit);
}
if (r1 == 1) {
if (bit) res[bit - 1] = 1;
}
if (r1 == -1) {
if (bit) res[bit - 1] = -1;
}
} else {
if (r1 == 1 && r2 == -1) {
a |= (1 << bit);
}
if (r1 == -1 && r2 == 1) {
b |= (1 << bit);
}
}
}
}
cout << "! " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int res;
bitset<30> a, b;
int aa = 11, bb = 22;
bool rever;
void query() {
if (rever) {
printf("? %u %u\n", b.to_ulong(), a.to_ulong());
} else {
printf("? %u %u\n", a.to_ulong(), b.to_ulong());
}
fflush(stdout);
scanf("%d", &res);
if (rever) {
res *= -1;
}
}
int main() {
int big = 0;
query();
big = res;
for (int i = 29; i >= 0; i--) {
if (big == 0) {
a[i] = 1;
query();
if (res == 1) {
a[i] = 0;
} else if (res == -1) {
b[i] = 1;
}
} else {
rever = false;
if (big == -1) {
swap(a, b);
rever = true;
big = 1;
}
a[i] = 1;
b[i] = 1;
query();
if (res == 1) {
a[i] = 0;
query();
if (res == -1) {
b[i] = 0;
} else {
a[i] = 1;
}
} else if (res == -1) {
b[i] = 0;
query();
big = res;
}
if (rever) {
swap(a, b);
big *= -1;
}
}
}
printf("! %u %u\n", a.to_ulong(), b.to_ulong());
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans[2];
void solve(int t) {
int x;
for (int i = t; i >= 0; i--) {
printf("? %d %d\n", ans[0] | (1 << i), ans[1]);
cin >> x;
if (x == -1) {
ans[0] |= (1 << i);
ans[1] |= (1 << i);
}
}
return;
}
int main() {
int x, flag = 0;
printf("? 0 0\n");
cin >> flag;
for (int i = 29; i >= 0; i--) {
printf("? %d %d\n", ans[0] | (1 << i), ans[1] | (1 << i));
cin >> x;
if (x == 0) {
solve(i);
break;
}
if (x == flag) {
printf("? %d %d\n", ans[0] | (1 << i), ans[1]);
cin >> x;
if (x == -1) {
ans[0] |= (1 << i);
ans[1] |= (1 << i);
}
} else {
if (x == 1) {
ans[1] |= (1 << i);
printf("? %d %d\n", ans[0], ans[1]);
cin >> flag;
} else {
ans[0] |= (1 << i);
printf("? %d %d\n", ans[0], ans[1]);
cin >> flag;
}
}
}
printf("! %d %d\n", ans[0], ans[1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
int main() {
long long ruijou[65];
ruijou[0] = 1;
for (int i = 0; i < 30; i++) ruijou[i + 1] = 2 * ruijou[i];
long long a = 0, b = 0;
cout << "? 0 0" << endl;
fflush(stdout);
int flag;
cin >> flag;
int keta = 29;
while (keta >= 0) {
int tmp_a, tmp_b;
int ans1, ans2;
printf("? %lld %lld\n", a + ruijou[keta], b);
fflush(stdout);
cin >> ans1;
printf("? %lld %lld\n", a, ruijou[keta] + b);
fflush(stdout);
cin >> ans2;
if (flag == -1) {
if (ans1 == -1 and ans2 == -1) {
tmp_a = 0;
tmp_b = 1;
} else if (ans1 == -1 and ans2 == 1) {
tmp_a = 1;
tmp_b = 1;
} else if (ans1 == 1 and ans2 == -1) {
tmp_a = 0;
tmp_b = 0;
} else if (ans1 == 1 and ans2 == 1) {
tmp_a = 0;
tmp_b = 1;
} else {
if (flag == 1)
a += ruijou[keta];
else
b += ruijou[keta];
flag = 0;
break;
}
a += tmp_a * ruijou[keta];
b += tmp_b * ruijou[keta];
if (ans1 == 1 and ans2 == 1) flag *= -1;
keta -= 1;
} else {
if (ans1 == -1 and ans2 == -1) {
tmp_a = 1;
tmp_b = 0;
} else if (ans1 == -1 and ans2 == 1) {
tmp_a = 1;
tmp_b = 1;
} else if (ans1 == 1 and ans2 == -1) {
tmp_a = 0;
tmp_b = 0;
} else if (ans1 == 1 and ans2 == 1) {
tmp_a = 1;
tmp_b = 0;
} else {
if (flag == 1)
a += ruijou[keta];
else
b += ruijou[keta];
flag = 0;
break;
}
a += tmp_a * ruijou[keta];
b += tmp_b * ruijou[keta];
if (ans1 == -1 and ans2 == -1) flag *= -1;
keta -= 1;
}
}
if (flag == 0 and keta > 0) {
while (keta > 0) {
keta -= 1;
printf("? %lld %lld\n", a + ruijou[keta], b);
fflush(stdout);
int ans1;
cin >> ans1;
if (ans1 == 1)
continue;
else {
a += ruijou[keta];
b += ruijou[keta];
}
}
}
printf("! %lld %lld\n", a, b);
}
|
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
const long long int MAXN = (long long int)1e6 + 20;
const long long int N = (long long int)1e5 + 10;
const long long int MOD = (long long int)1e9 + 7;
long long int query(long long int c, long long int d) {
cout << "? " << c << " " << d << endl;
long long int ans;
cin >> ans;
return ans;
}
void solve() {
long long int a = 0, b = 0;
long long int bigger = query(0, 0);
for (long long int i = 29; i >= 0; --i) {
long long int frst = query(a | (1 << i), b);
long long int sec = query(a, b | (1 << i));
if (frst == sec) {
if (bigger == 1) {
a |= (1 << i);
} else {
b |= (1 << i);
}
bigger = frst;
} else if (frst == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
cout << "! " << a << " " << b << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
bitset<30> a;
bitset<30> b;
a.reset();
b.reset();
bool bigger = 0;
cout << "? 0 0" << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == -1) {
bigger = 1;
}
bitset<30> adda;
bitset<30> addb;
for (int i = 29; i >= 0; i--) {
adda[i] = 1;
addb[i] = 1;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == -1 && bigger == 0) {
a[i] = 1;
b[i] = 0;
adda[i] = 0;
addb[i] = 1;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == -1) {
bigger = 1;
}
} else if (aa == 1 && bigger == 1) {
a[i] = 0;
b[i] = 1;
adda[i] = 1;
addb[i] = 0;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == 1) {
bigger = 0;
}
} else if (aa == 1 && bigger == 0) {
adda[i] = 1;
addb[i] = 0;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == 1) {
a[i] = 0;
b[i] = 0;
adda[i] = 0;
addb[i] = 0;
} else if (aa == -1) {
a[i] = 1;
b[i] = 1;
adda[i] = 1;
addb[i] = 1;
}
} else if (aa == -1 && bigger == 1) {
adda[i] = 0;
addb[i] = 1;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == -1) {
a[i] = 0;
b[i] = 0;
adda[i] = 0;
addb[i] = 0;
} else if (aa == 1) {
a[i] = 1;
b[i] = 1;
adda[i] = 1;
addb[i] = 1;
}
} else if (aa == 0) {
adda[i] = 0;
addb[i] = 1;
cout << "? " << adda.to_ulong() << ' ' << addb.to_ulong() << endl;
fflush(stdout);
int aa;
cin >> aa;
if (aa == -1) {
a[i] = 0;
b[i] = 0;
adda[i] = 0;
addb[i] = 0;
} else if (aa == 1) {
a[i] = 1;
b[i] = 1;
adda[i] = 1;
addb[i] = 1;
}
}
}
cout << "! " << a.to_ulong() << ' ' << b.to_ulong() << endl;
fflush(stdout);
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
template <class T>
using V = vector<T>;
template <class T, size_t SZ>
using AR = array<T, SZ>;
template <class T>
using PR = pair<T, T>;
template <class T>
int lwb(V<T> &a, const T &b) {
return int(lower_bound(begin(a), end(a), b) - begin(a));
}
const int MOD = 1e9 + 7;
const int MODD = 998244353;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(
(uint64_t)chrono::steady_clock::now().time_since_epoch().count());
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int largest_bit(int x) { return x == 0 ? -1 : 31 - __builtin_clz(x); }
constexpr ll p2(ll x) { return 1LL << x; }
constexpr ll msk2(ll x) { return p2(x) - 1; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template <class T>
bool ckmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <class T, class U>
T fstTrue(T lo, T hi, U first) {
hi++;
assert(lo <= hi);
while (lo < hi) {
T mid = lo + (hi - lo) / 2;
first(mid) ? hi = mid : lo = mid + 1;
}
return lo;
}
template <class T, class U>
T lstTrue(T lo, T hi, U first) {
lo--;
assert(lo <= hi);
while (lo < hi) {
T mid = lo + (hi - lo + 1) / 2;
first(mid) ? lo = mid : hi = mid - 1;
}
return lo;
}
template <class T>
void remDup(vector<T> &v) {
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
}
template <class T, class U>
void erase(T &t, const U &u) {
auto it = t.find(u);
assert(it != end(t));
t.erase(it);
}
int query(int c, int d) {
cout << "? " << c << " " << d << endl;
int res;
cin >> res;
return res;
}
void solve() {
int a = 0, b = 0, prev = 0;
bool both_bit_same = false;
for (int i = (30) - 1; i >= (0); --i) {
int unset_res;
if (both_bit_same) {
unset_res = prev;
} else {
unset_res = query(a, b);
}
int set_res = query(a | (1 << i), b | (1 << i));
if (unset_res == set_res) {
both_bit_same = true;
prev = set_res;
int one_or_zero = query(a | (1 << i), b);
if (one_or_zero == -1) {
a |= 1 << i;
b |= 1 << i;
}
} else {
both_bit_same = false;
if (unset_res == 1) {
a |= 1 << i;
} else {
b |= 1 << i;
}
}
}
cout << "! " << a << " " << b;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
cout << "? " << c << ' ' << d << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
int a = 0, b = 0, big = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
if (f == s) {
if (big == 1)
a ^= (1 << i);
else
b ^= (1 << i);
big = f;
} else if (f == -1) {
a ^= 1 << i;
b ^= 1 << i;
}
}
cout << "! " << a << ' ' << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long int l = v.size();
for (long long int i = 0; i < l - 1; i++) out << v[i] << ' ';
if (l > 0) out << v[l - 1];
return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
trace(comma + 1, args...);
}
long long int gcd(long long int a, long long int b) {
if (b < a) {
swap(a, b);
}
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
return (a * b / gcd(a, b));
}
long long int primefactorise(int n) {
if (n == 1) {
return 1;
}
long long int ans = n;
while (n % 2 == 0) {
n = n / 2;
if (n != 1) {
ans += n;
}
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
n = n / i;
if (n != 1) {
ans += n;
}
}
}
ans += 1;
return ans;
}
long long int power(long long int a, long long int b) {
long long int ans = 1;
while (b > 0) {
if (b % 2 == 1) {
ans *= a;
ans = ans;
}
b /= 2;
a *= a;
a = a;
}
return ans;
}
vector<long long int> getbinary(long long int x, long long int size) {
vector<long long int> bin(size, 0);
long long int iter = 0;
while (x > 0) {
if (x % 2 == 0) {
bin[iter] = 0;
} else {
bin[iter] = 1;
}
x /= 2;
iter++;
}
return bin;
}
long long int dist(pair<long long int, long long int> a,
pair<long long int, long long int> b) {
return 0;
}
vector<long long int> getprimes() {
vector<long long int> primes(1000000, 0);
vector<long long int> ans;
for (int i = 2; i < 1000000; i++) {
if (primes[i] == 0) {
for (int j = 2 * i; j < 1000000; j += i) {
primes[j] = 1;
}
ans.push_back(i);
}
}
return ans;
}
const long long int size = 10;
struct tnode {
tnode* child[size];
long long int isword;
};
tnode* makenode() {
tnode* temp = new tnode;
for (int i = 0; i < size; i++) {
temp->child[i] = NULL;
}
temp->isword = 0;
return temp;
}
void insert(tnode* root, string second) {
tnode* temp = root;
for (int i = 0; i < second.size(); i++) {
long long int key = second[i] - 'a';
if (temp->child[key] == NULL) {
temp->child[key] = makenode();
}
temp = temp->child[key];
}
temp->isword = 1;
}
long long int search(tnode* root, string second) {
tnode* temp = root;
for (int i = 0; i < second.size(); i++) {
long long int key = second[i] - 'a';
if (temp->child[key] == NULL) {
return 0;
}
temp = temp->child[key];
}
return temp->isword;
}
int query(int a, int b) {
cout << "? " << a << " " << b << endl;
long long int ans;
cin >> ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(50);
cout.flush();
long long int a = 0, b = 0, maxnum = query(0, 0);
for (int i = 29; i >= 0; i--) {
long long int temp1 = query(a ^ power(2, i), b);
long long int temp2 = query(a, b ^ power(2, i));
if (temp1 == temp2) {
if (maxnum == 1) {
a ^= power(2, i);
} else {
b ^= power(2, i);
}
maxnum = temp1;
} else {
if (temp2 == 1) {
a ^= power(2, i);
b ^= power(2, i);
}
}
}
cout << "! " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int get() {
fflush(stdout);
int x;
cin >> x;
return x;
}
int main() {
cout << "? 0 0" << endl;
int sta = get(), ansa = 0, ansb = 0;
for (int i = 29; i >= 0; i--) {
int tmp = 1 << i;
if (sta == 0) {
cout << "? " << (ansa | tmp) << " " << ansb << endl;
int now = get();
if (now == -1) ansa |= tmp, ansb |= tmp;
} else {
cout << "? " << (ansa | tmp) << " " << (ansb | tmp) << endl;
int now = get();
if (sta == now) {
if (sta == -1) {
cout << "? " << (ansa | tmp) << " " << ansb << endl;
int now = get();
if (now == 0) ansb |= tmp, sta = 0;
if (now == -1) ansa |= tmp, ansb |= tmp;
} else {
cout << "? " << ansa << " " << (ansb | tmp) << endl;
int now = get();
if (now == 0) ansa |= tmp, sta = 0;
if (now == 1) ansa |= tmp, ansb |= tmp;
}
} else {
if (sta == 1 && now == -1) {
ansa |= tmp;
cout << "? " << ansa << " " << ansb << endl;
sta = get();
} else {
ansb |= tmp;
cout << "? " << ansa << " " << ansb << endl;
sta = get();
}
}
}
}
cout << "! " << ansa << " " << ansb << endl;
fflush(stdout);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[30];
int b[30];
printf("? %d %d\n", 0, 0);
fflush(stdout);
int x;
cin >> x;
long long int p = pow(2, 29);
long long int q = 0;
long long int c = 0;
long long int d = 0;
for (int i = 0; i < 30; i++) {
c = c + p;
d = d + q;
printf("? %lld %lld\n", c, d);
fflush(stdout);
int y;
cin >> y;
c = c - p + q;
d = d - q + p;
printf("? %lld %lld\n", c, d);
fflush(stdout);
int z;
cin >> z;
c = c - q + p;
d = d - p + q;
if (y == -1 && z == 1) {
a[i] = 1;
b[i] = 1;
} else if (y == 1 && z == -1) {
a[i] = 0;
b[i] = 0;
} else if (y == z) {
if (x == 1) {
a[i] = 1;
b[i] = 0;
if (y == 1)
x = 1;
else if (y == -1)
x = -1;
} else if (x == -1) {
a[i] = 0;
b[i] = 1;
if (y == 1)
x = 1;
else if (y == -1)
x = -1;
}
}
if (a[i] == 0) c = c - p;
if (b[i] == 0)
d = d - q;
else if (b[i] == 1)
d = d + p;
p = p / 2;
}
long long int u = 0;
long long int t = 1;
for (int i = 29; i >= 0; i--) {
u = u + a[i] * t;
t = t * 2;
}
long long int v = 0;
t = 1;
for (int i = 29; i >= 0; i--) {
v = v + b[i] * t;
t = t * 2;
}
printf("! %lld %lld\n", u, v);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a, b, in;
long long shift(long long i) { return (1 << i); }
void getx(long long x, long long y) {
cout << "? " << x << " " << y << endl;
cin >> in;
return;
}
int main() {
ios_base::sync_with_stdio(false);
long long curbit = 29;
getx(0, 0);
long long start = in;
while (curbit >= 0) {
if (start == 0) {
getx(a ^ shift(curbit), b);
if (in == -1) {
a |= shift(curbit);
b |= shift(curbit);
getx(a, b);
start = in;
}
curbit--;
continue;
}
getx(a ^ shift(curbit), b ^ shift(curbit));
while (in == start) {
if (start == 1) {
getx(a ^ shift(curbit), b);
if (in == -1) {
a |= shift(curbit);
b |= shift(curbit);
}
} else {
getx(a, b ^ shift(curbit));
if (in == 1) {
a |= shift(curbit);
b |= shift(curbit);
}
}
if (curbit == 0) break;
curbit--;
getx(a ^ shift(curbit), b ^ shift(curbit));
}
if (in != start) {
if (start == 1)
a |= shift(curbit);
else if (start == 0) {
a |= shift(curbit);
b |= shift(curbit);
} else
b |= shift(curbit);
getx(a, b);
start = in;
}
curbit--;
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int powe(int x, int y) {
x = x % mod;
int ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long prev, r1, r2, a = 0, b = 0;
cout << "? 0 0" << endl;
cin >> prev;
for (int i = 29; i >= 0; i--) {
if (prev == 1) {
cout << "? " << (a | (1 << i)) << " " << b << endl;
cin >> r1;
cout << "? " << (a | (1 << i)) << " " << (b | (1 << i)) << endl;
cin >> r2;
if (r2 == -1) {
prev = r1;
a = (a | (1 << i));
} else if (r1 == -1) {
a = a | (1 << i);
b = b | (1 << i);
}
} else if (prev == -1) {
cout << "? " << a << " " << (b | (1 << i)) << endl;
cin >> r1;
cout << "? " << (a | (1 << i)) << " " << (b | (1 << i)) << endl;
cin >> r2;
if (r2 == 1) {
prev = r1;
b = (b | (1 << i));
} else if (r1 == 1) {
a = a | (1 << i);
b = b | (1 << i);
}
} else {
cout << "? " << (a | 1 << i) << " " << b << endl;
cin >> r1;
if (r1 == -1) {
a = a | (1 << i);
b = b | (1 << i);
}
}
}
cout << "! " << a << " " << b;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MOD = 1e9 + 7;
long long a, b, c, d, comp, dl;
int query(long long c, long long d) {
printf("? %lld %lld\n", c, d);
fflush(stdout);
int ans;
scanf("%d", &ans);
if (ans == -2) c /= 0;
return ans;
}
int main() {
dl = query(0, 0);
for (int i = 29; i >= 0; i--) {
if (dl != 0) {
if (query(c + (1 << i), d + (1 << i)) == dl) {
if (query(c + (1 << i), d) == -1) {
c += (1 << i);
d += (1 << i);
}
} else {
if (dl == 1) {
dl = query(c + (1 << i), d);
c += (1 << i);
} else {
dl = query(c, d + (1 << i));
d += (1 << i);
}
}
} else {
if (query(c + (1 << i), d) == -1) {
c += (1 << i);
d += (1 << i);
}
}
}
printf("! %lld %lld\n", c, d);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(long long a, long long b) {
int ret = 0;
cout << "? " << a << ' ' << b << endl;
cout.flush();
cin >> ret;
return ret;
}
void ans(long long a, long long b) {
cout << "! " << a << ' ' << b << endl;
cout.flush();
return;
}
int pre;
int c, d;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pre = ask(0, 0);
for (int pos = 29; pos >= 0; pos--) {
int nan1 = ask(c | (1 << pos), d | (1 << pos));
if (nan1 == pre) {
int n2 = ask(c | (1 << pos), d | (0 << pos));
if (n2 == 1) {
} else {
c = c | (1 << pos);
d = d | (1 << pos);
pre = nan1;
}
} else {
if (pre == -1) {
d = d | (1 << pos);
pre = ask(c, d);
} else {
c = c | (1 << pos);
pre = ask(c, d);
}
}
}
ans(c, d);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int query(int x, int y) {
cout << "? " << x << " " << y << "\n";
cout.flush();
int a;
cin >> a;
return a;
}
int main() {
int a = 0, b = 0, c = query(0, 0);
for (int i = 29; i >= 0; i--) {
int A = query(a ^ (1 << i), b), B = query(a, b ^ (1 << i));
if (A == B) {
if (c == 1)
a ^= (1 << i);
else
b ^= (1 << i);
c = A;
} else if (A == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << " " << b << "\n";
cout.flush();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int a, int b) {
cout << "? " << a << ' ' << b << endl;
int res;
cin >> res;
return res;
}
int main() {
cout.flush();
int currA(0), currB(0);
int aIsBig = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(currA ^ (1 << i), currB);
int s = ask(currA, currB ^ (1 << i));
if (f == s) {
if (aIsBig == 1) {
currA ^= (1 << i);
} else {
currB ^= (1 << i);
}
aIsBig = f;
} else if (f == -1) {
currA ^= (1 << i);
currB ^= (1 << i);
}
}
cout << "! " << currA << " " << currB << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
cout << "? " << c << " " << d << endl;
fflush(stdout);
int x;
cin >> x;
return x;
}
void go(int a, int b) {
cout << "! " << a << " " << b << endl;
fflush(stdout);
exit(0);
}
bool same[50];
signed main() {
int type = ask(0, 0);
if (type == 0) {
int ans = 0;
for (int i = 29; i >= 0; i--) {
int q = ask((1 << i), 0);
if (q == 0) {
continue;
}
if (q == 1) {
ans += 0;
} else {
ans += (1 << i);
}
}
go(ans, ans);
}
bool A, B;
if (type == 1) {
A = 1;
B = 0;
} else {
A = 0;
B = 1;
}
int ansA = 0, ansB = 0;
for (int i = 29; i >= 0; i--) {
int q = ask(ansA + (1 << i), ansB + (1 << i));
if (q == 0) {
for (int pos = i; pos >= 0; pos--) {
same[pos] = 1;
}
break;
}
if (A == 1) {
if (q == 1) {
same[i] = 1;
} else {
ansA += (1 << i);
ansB += 0;
int qq = ask(ansA, ansB);
if (qq == 1) A = 1, B = 0;
if (qq == -1) A = 0, B = 1;
}
} else {
if (q == -1) {
same[i] = 1;
} else {
ansA += 0;
ansB += (1 << i);
int qq = ask(ansA, ansB);
if (qq == 1) A = 1, B = 0;
if (qq == -1) A = 0, B = 1;
}
}
}
for (int i = 29; i >= 0; i--) {
if (same[i]) {
int q = ask(ansA + (1 << i), ansB);
if (q == 0) {
continue;
}
if (q == 1) {
ansA += 0;
ansB += 0;
} else {
ansA += (1 << i);
ansB += (1 << i);
}
}
}
go(ansA, ansB);
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int a[35], b[35];
int nowa, nowb;
int T = 0;
void smaller(int x);
int query(int a, int b, int type = 0) {
if (type) {
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
T++;
if (T > 62) assert(false);
printf("? %d %d\n", a, b);
fflush(stdout);
int t;
scanf("%d", &t);
return t;
}
void getans() {
int ansa = 0, ansb = 0;
for (int i = 0; i < N; i++) {
ansa = ansa * 2 + a[i];
ansb = ansb * 2 + b[i];
}
query(ansa, ansb, 1);
}
void equall(int x) {
for (int i = x; i < N; i++) {
nowa |= (1 << (N - 1 - i));
int t = query(nowa, nowb);
if (t < 0)
a[i] = b[i] = 1;
else
a[i] = b[i] = 0;
nowb |= (1 << (N - 1 - i));
}
getans();
}
void bigger(int x) {
if (x == N) {
getans();
return;
}
nowb |= (1 << (N - 1 - x));
int t = query(nowa, nowb);
if (t > 0) {
nowa |= (1 << (N - 1 - x));
nowb ^= (1 << (N - 1 - x));
t = query(nowa, nowb);
if (t == 0) {
a[x] = 1;
b[x] = 0;
equall(x + 1);
}
if (t > 0) {
a[x] = 1;
b[x] = 0;
bigger(x + 1);
}
if (t < 0) {
a[x] = 1;
b[x] = 1;
nowa ^= (1 << (N - 1 - x));
bigger(x + 1);
}
} else if (t < 0) {
nowa |= (1 << (N - 1 - x));
nowb ^= (1 << (N - 1 - x));
t = query(nowa, nowb);
if (t == 0) {
a[x] = 1;
b[x] = 0;
equall(x + 1);
}
if (t < 0) {
a[x] = 1;
b[x] = 0;
smaller(x + 1);
}
if (t > 0) {
a[x] = 0;
b[x] = 0;
nowa ^= (1 << (N - 1 - x));
bigger(x + 1);
}
} else {
a[x] = 1;
b[x] = 0;
equall(x + 1);
}
}
void smaller(int x) {
if (x == N) {
getans();
return;
}
nowb |= (1 << (N - 1 - x));
int t = query(nowa, nowb);
if (t > 0) {
nowa |= (1 << (N - 1 - x));
nowb ^= (1 << (N - 1 - x));
t = query(nowa, nowb);
if (t == 0) {
a[x] = 0;
b[x] = 1;
equall(x + 1);
}
if (t > 0) {
a[x] = 0;
b[x] = 1;
bigger(x + 1);
}
if (t < 0) {
a[x] = 1;
b[x] = 1;
nowa ^= (1 << (N - 1 - x));
smaller(x + 1);
}
} else if (t < 0) {
nowa |= (1 << (N - 1 - x));
nowb ^= (1 << (N - 1 - x));
t = query(nowa, nowb);
if (t == 0) {
a[x] = 0;
b[x] = 1;
equall(x + 1);
}
if (t < 0) {
a[x] = 0;
b[x] = 1;
smaller(x + 1);
}
if (t > 0) {
a[x] = 0;
b[x] = 0;
nowa ^= (1 << (N - 1 - x));
smaller(x + 1);
}
} else {
a[x] = 0;
b[x] = 1;
equall(x + 1);
}
}
int main() {
int t = query(0, 0);
if (t == 0) {
equall(0);
}
if (t > 0) bigger(0);
if (t < 0) smaller(0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long a = (1 << 30), b = (1 << 30);
unsigned long ansa = 0x0, ansb = 0x0;
int diff, q1, q;
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &diff);
for (int k = 1; k <= 30; k++) {
a = (ansa)&0xffffffff;
b = (ansb)&0xffffffff;
a |= (1 << (30 - k));
printf("? %lu %lu\n", a, b);
fflush(stdout);
scanf("%d", &q);
b |= (1 << (30 - k));
a ^= (1 << (30 - k));
printf("? %lu %lu\n", a, b);
fflush(stdout);
scanf("%d", &q1);
if (q != q1) {
if (q == -1) {
ansa |= (1 << (30 - k));
ansb |= (1 << (30 - k));
}
} else {
if (diff == 1) {
ansa |= (1 << (30 - k));
} else {
ansb |= (1 << (30 - k));
}
diff = q;
}
}
printf("! %ld %ld", ansa, ansb);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a = 0;
int b = 0;
int ok;
int qry(int a, int b) {
cout << "? " << a << " " << b << endl;
int ans;
cin >> ans;
return ans;
}
int main() {
int ok = qry(0, 0);
for (int i = 29; i >= 0; i--) {
int cura = a | (1 << i);
int curb = b | (1 << i);
int ans1 = qry(a, curb);
int ans2 = qry(cura, b);
if (ans1 == ans2) {
if (ok == 1) {
a = cura;
ok = ans1;
} else {
b = curb;
ok = ans2;
}
} else {
if (ans1 != -1) {
a = cura;
b = curb;
}
}
}
cout << "! " << a << ' ' << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int sa, sb, f, a, b;
int ask(int c, int d) {
cout << "? " << c << " " << d << "\n";
fflush(stdout);
int x;
scanf("%d", &x);
return x;
}
void wt(int c, int d) {
cout << "! " << c << " " << d << "\n";
fflush(stdout);
}
int main() {
f = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int x = ask(a ^ (1 << i), b ^ (1 << i));
if (x == f) {
int u = ask((1 << i) ^ a, b);
if (u == -1) {
a |= (1 << i);
b |= (1 << i);
}
} else {
if (f == 1)
a |= (1 << i);
else
b |= (1 << i);
f = ask(a, b);
}
}
wt(a, b);
return 0;
}
|
#include <bits/stdc++.h>
long int* a = new long int[30];
void bin_cout(long int b_1, long int b_2) {
for (int i = 29; i > -1; i--) {
std::cout << (bool)(b_1 & a[i]);
}
std::cout << " ";
for (int i = 29; i > -1; i--) {
std::cout << (bool)(b_2 & a[i]);
}
std::cout << std::endl;
};
int main() {
for (int i = -1; i <= 28; i++) {
a[i + 1] = pow(2, i + 1);
}
long int c, d, l = pow(2, 30) - 1;
long int s_a = 0, s_b = 0;
int answ1, answ2, answ3 = -2;
for (int i = 29; i >= 0; i--) {
std::cout << "? " << a[i] + s_a << " " << s_b << std::endl;
fflush(stdout);
std::cin >> answ1;
std::cout << "? " << s_a << " " << a[i] + s_b << std::endl;
fflush(stdout);
std::cin >> answ2;
if (answ1 != answ2) {
if (answ1 < answ2) {
s_a += a[i];
s_b += a[i];
}
} else {
if (answ3 == -2) {
std::cout << "? " << (l & s_a) << " " << (l & s_b) << std::endl;
fflush(stdout);
std::cin >> answ3;
}
switch (answ3) {
case (1):
s_a += a[i];
answ3 = answ1;
break;
case (-1):
s_b += a[i];
answ3 = answ1;
break;
}
}
}
std::cout << "! " << s_a << " " << s_b << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void ask0(int idx);
void askn1(int idx);
int C = 0, D = 0;
void ask1(int idx) {
if (idx == -1) {
return;
}
int x = (C | (1 << idx)), y = (D | (1 << idx));
printf("? %d %d\n", x, y);
fflush(stdout);
int T;
scanf("%d", &T);
if (T == 1) {
y = D;
printf("? %d %d\n", x, y);
fflush(stdout);
int R;
scanf("%d", &R);
if (R == -1) {
C |= (1 << idx);
D |= (1 << idx);
}
ask1(idx - 1);
} else {
C = x;
int t;
printf("? %d %d\n", C, D);
fflush(stdout);
scanf("%d", &t);
if (t == 1) {
ask1(idx - 1);
} else if (t == 0) {
ask0(idx - 1);
} else {
askn1(idx - 1);
}
}
}
void ask0(int idx) {
if (idx == -1) {
return;
}
int x = (C | (1 << idx));
printf("? %d %d\n", x, D);
fflush(stdout);
int T;
scanf("%d", &T);
if (T == -1) {
C = x;
D |= (1 << idx);
}
ask0(idx - 1);
}
void askn1(int idx) {
if (idx == -1) {
return;
}
int x = (C | (1 << idx)), y = (D | (1 << idx));
printf("? %d %d\n", x, y);
fflush(stdout);
int T;
scanf("%d", &T);
if (T == -1) {
y = D;
printf("? %d %d\n", x, y);
fflush(stdout);
int R;
scanf("%d", &R);
if (R == -1) {
C |= (1 << idx);
D |= (1 << idx);
}
askn1(idx - 1);
} else {
D = y;
int t;
printf("? %d %d\n", C, D);
fflush(stdout);
scanf("%d", &t);
if (t == 1) {
ask1(idx - 1);
} else if (t == 0) {
ask0(idx - 1);
} else {
askn1(idx - 1);
}
}
}
int main() {
printf("? %d %d\n", C, D);
fflush(stdout);
int t;
scanf("%d", &t);
if (t == 1) {
ask1(29);
} else if (t == 0) {
ask0(29);
} else {
askn1(29);
}
printf("! %d %d\n", C, D);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int question(int c, int d) {
int ans;
cout << "? " << c << " " << d << endl;
fflush(stdout);
cin >> ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int f, s, a = 0, b = 0;
int big = question(0, 0);
for (int i = 29; i >= 0; --i) {
f = question(a | (1 << i), b);
s = question(a, b | (1 << i));
if (f == s) {
if (big == 1)
a |= (1 << i);
else
b |= (1 << i);
big = f;
} else {
if (f == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)2e6 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
long long dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
long long A = 3, B = 1;
long long ask(long long x, long long y, long long s) {
cout << "? " << x << ' ' << y << '\n';
fflush(stdout);
long long e;
cin >> e;
fflush(stdout);
return e;
}
void solve() {
long long a = 0, b = 0;
long long big = ask(0, 0, 0);
for (long long i = 29; i >= 0; i--) {
long long s = (1LL << i);
long long p1, p2;
p1 = ask(a | s, b, s);
p2 = ask(a, b | s, s);
if (p1 == p2) {
if (big == 1)
a |= s;
else
b |= s;
big = p1;
} else {
if (p1 == -1) a |= s, b |= s;
}
}
cout << "! " << a << ' ' << b << '\n';
fflush(stdout);
return;
}
int main() {
long long T;
T = 1;
long long CT = 0;
while (T--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
auto get = [&](long long c, long long d) {
cout << "? " << c << " " << d << endl;
cout.flush();
long long val;
cin >> val;
return val;
};
auto print = [&](long long a, long long b) {
cout << "! " << a << " " << b << endl;
cout.flush();
};
long long AgrtB = get(0, 0);
long long curA = 0, curB = 0;
for (long long i = 29; i >= 0; i--) {
long long bit = 1 << i;
long long v1 = get(curA ^ bit, curB);
long long v2 = get(curA, curB ^ bit);
if (v1 != v2) {
if (v1 == -1) {
curA = curA ^ bit;
curB = curB ^ bit;
}
} else {
if (AgrtB == 1) {
curA = curA ^ bit;
} else {
curB = curB ^ bit;
}
AgrtB = v1;
}
}
print(curA, curB);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int N, M;
int cmp[35][2][2];
int ans[35][2];
int main() {
memset(cmp, 1, sizeof(cmp));
int base0 = 0;
int base1 = 0;
for (int i = 29; i >= 0; i--) {
if (cmp[i][0][0] == (16843009)) {
++N;
printf("? %d %d\n", base0, base1);
fflush(stdout);
cin >> cmp[i][0][0];
}
if (cmp[i][0][0] == 0) {
if (i > 1) cmp[i - 1][0][0] = cmp[i][0][0];
++N;
printf("? %d %d\n", base0 + (1 << i), base1);
fflush(stdout);
cin >> cmp[i][1][0];
if (cmp[i][1][0] == 1)
ans[i][0] = ans[i][1] = 0;
else
ans[i][0] = ans[i][1] = 1, base0 += (1 << i), base1 += (1 << i);
continue;
}
++N;
printf("? %d %d\n", base0 + (1 << i), base1 + (1 << i));
fflush(stdout);
cin >> cmp[i][1][1];
if (cmp[i][0][0] == cmp[i][1][1]) {
++N;
printf("? %d %d\n", base0 + (1 << i), base1);
fflush(stdout);
cin >> cmp[i][1][0];
if (cmp[i][1][0] == 1)
ans[i][0] = ans[i][1] = 0;
else
ans[i][0] = ans[i][1] = 1, base0 += (1 << i), base1 += (1 << i);
if (i > 1) cmp[i - 1][0][0] = cmp[i][0][0];
} else {
if (cmp[i][0][0] == 1)
ans[i][0] = 1, ans[i][1] = 0, base0 += (1 << i);
else
ans[i][0] = 0, ans[i][1] = 1, base1 += (1 << i);
}
}
int a = 0, b = 0;
for (int i = 29; i >= 0; i--) {
if (ans[i][0]) a += (1 << i);
if (ans[i][1]) b += (1 << i);
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
int main() {
bool f = false;
std::cout << "? 0 0" << std::endl;
int t;
std::cin >> t;
int a = 0, b = 0, x, y;
for (int i = 29; i >= 0; --i) {
std::cout << "? " << (a ^ (1 << i)) << " " << b << std::endl;
std::cin >> x;
std::cout << "? " << a << " " << (b ^ (1 << i)) << std::endl;
std::cin >> y;
if (x == y) {
((t == 1) ? a : b) ^= 1 << i;
t = x;
} else if (x == -1) {
a ^= 1 << i;
b ^= 1 << i;
}
}
std::cout << "! " << a << " " << b << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
const double PI = acos(-1);
const double EPS = 1e-6;
const long long MOD = 998244353;
const long long N = 30 + 10;
template <typename T>
inline T Abs(T x) {
return x < 0 ? x * -1 : x;
}
template <typename T>
inline T Max(T x, T y, T z) {
return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z) {
return std::min(std::min(x, y), z);
}
template <typename T>
inline void Ckmax(T &x, T y) {
x = std::max(x, y);
}
template <typename T>
inline void Ckmin(T &x, T y) {
x = std::min(x, y);
}
template <typename T>
inline T Sqr(T x) {
return x * x;
}
template <typename T>
inline T Pow(T x, T y) {
T r = 1;
while (y > 0) {
if (y % 2 > 0) (r *= x) %= MOD;
(x *= x) %= MOD;
y /= 2;
}
return r % MOD;
}
template <typename T>
T Pow(T x, T y, T z) {
T r = 1;
while (y > 0) {
if (y % 2 > 0) (r *= x) %= z;
(x *= x) %= z;
y /= 2;
}
return r % z;
}
template <typename T>
inline T gcd(T x, T y) {
return y > 0 ? gcd(y, x % y) : x;
}
template <typename T>
inline T lcm(T x, T y) {
return x / gcd(x, y) * y;
}
inline void cinspu(void) {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
}
inline long long fac(long long x) {
long long r = 1;
for (; x > 1; --x) (r *= x) %= MOD;
return r;
}
int a[N], b[N], ans[N], tim;
int print(char z, int x, int y) {
++tim;
printf("%c %d %d\n", z, x, y);
fflush(stdout);
if (z == '?') {
int r;
scanf("%d", &r);
return r;
}
return -2;
}
int main() {
const char q = '?';
for (int i = 29, x = 0, y = 0; i >= 0; --i) {
int n = (1 << i), r;
if (ans[i])
r = ans[i] - 3;
else
r = print(q, x, y);
if (r > 0) {
int p = print(q, x + n, y + n);
if (p > 0) {
int t = print(q, x + n, y);
if (t > 0) {
a[i] = b[i] = 0;
ans[i - 1] = 3 + r;
} else {
a[i] = b[i] = 1;
ans[i - 1] = 3 + p;
x += n;
y += n;
}
} else {
a[i] = 1;
b[i] = 0;
x += n;
}
} else if (r < 0) {
int p = print(q, x + n, y + n);
if (p < 0) {
int t = print(q, x + n, y);
if (t > 0) {
a[i] = b[i] = 0;
ans[i - 1] = 3 + r;
} else {
a[i] = b[i] = 1;
ans[i - 1] = 3 + p;
x += n;
y += n;
}
} else {
a[i] = 0;
b[i] = 1;
y += n;
}
} else {
r = print(q, x + n, y);
if (r > 0) {
a[i] = b[i] = 0;
} else {
a[i] = b[i] = 1;
x += n;
y += n;
}
}
}
int x = 0;
for (int i = 0; i < 30; ++i) x += a[i] * (1 << i);
int y = 0;
for (int i = 0; i < 30; ++i) y += b[i] * (1 << i);
print('!', x, y);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b = 0;
int res, mask1 = 0, mask2 = 0;
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &res);
int asli = res;
for (int i = 29; i >= 0; i--) {
mask1 = mask1 | (1 << i);
mask2 = mask2 | (1 << i);
printf("? %d %d\n", mask1, mask2);
fflush(stdout);
scanf("%d", &res);
if (res != asli) {
if (asli > 0) {
a = a | (1 << i);
mask2 = mask2 ^ (1 << i);
} else {
b = b | (1 << i);
mask2 = mask2 ^ (1 << i);
}
printf("? %d %d\n", mask1, mask2);
fflush(stdout);
scanf("%d", &res);
asli = res;
}
}
for (int i = 29; i >= 0; i--) {
if ((mask2 & (1 << i))) {
int c = mask1;
int d = mask2 ^ (1 << i);
printf("? %d %d\n", c, d);
fflush(stdout);
scanf("%d", &res);
if (res < 0) a = a | (1 << i), b = b | (1 << i);
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
long long md = 1000000007;
using namespace std;
template <typename T>
T pw(T a, T b) {
T c = 1, m = a;
while (b) {
if (b & 1) c = (c * m);
m = (m * m), b /= 2;
}
return c;
}
template <typename T>
T ceel(T a, T b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <typename T>
T my_log(T n, T b) {
T i = 1, ans = 0;
while (1) {
if (i > n) {
ans--;
break;
}
if (i == n) break;
i *= b, ans++;
}
return ans;
}
template <typename T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long pwmd(long long a, long long b) {
long long c = 1, m = a;
while (b) {
if (b & 1) c = (c * m) % md;
m = (m * m) % md;
b /= 2;
}
return c;
}
long long modinv(long long n) { return pwmd(n, md - 2); }
long long inverse(long long i) {
if (i == 1) return 1;
return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
int Query(int c, int d) {
cout << "? " << c << " " << d << "\n";
cout.flush();
int f;
cin >> f;
return f;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
vector<int> a(30), b(30);
int big, q1 = 0, q2 = 0;
big = Query(0, 0);
int pwe[30];
pwe[0] = 1;
for (int i = 1; i < 30; i++) pwe[i] = 2 * pwe[i - 1];
for (int i = 29; i >= 0; i--) {
int e, r = Query(q1 + (1 << i), q2 + (1 << i));
if (big >= 0)
e = Query(q1, q2 + (1 << i));
else
e = Query(q1 + (1 << i), q2);
if (big == 0) {
if (e > 0) a[i] = b[i] = 1, q1 += pwe[i], q2 += pwe[i];
continue;
} else if (big > 0) {
if (r < 0) {
a[i] = 1, q1 += pwe[i];
big = e;
} else {
if (e > 0) a[i] = b[i] = 1, big = r, q1 += pwe[i], q2 += pwe[i];
}
} else {
if (r > 0) {
b[i] = 1, q2 += pwe[i];
big = e;
} else {
if (e < 0) a[i] = b[i] = 1, big = r, q1 += pwe[i], q2 += pwe[i];
}
}
}
cout << "! " << q1 << " " << q2 << "\n";
cout.flush();
}
|
#include <bits/stdc++.h>
const int inf = (int)2e+9 + 2;
const int mod = (int)1e+5;
const int h_prime = 1103;
const double eps = 1e-6;
using namespace std;
vector<long long> primes;
vector<long long> HH, pp;
long double dist(pair<long double, long double> a,
pair<long double, long double> b) {
return sqrtl((a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second));
}
long double len(pair<long double, long double> x) {
return sqrtl(x.first * x.first + x.second * x.second);
}
long double angle(pair<long double, long double> a,
pair<long double, long double> b) {
return acos((a.first * b.first + a.second * b.second) / (len(a) * len(b)));
}
long double ar_tr(pair<long double, long double> a,
pair<long double, long double> b) {
return a.first * b.second - b.first * a.second;
}
long long get_hash(int l, int r) {
long long res = HH[r];
if (l) res -= HH[l - 1] * pp[r - l + 1];
return res;
}
void init_hashes(string s) {
long long hash = s[0];
HH.push_back(hash);
long long ppow = 1;
for (size_t i = 0; i < s.length(); ++i) {
pp.push_back(ppow);
ppow *= h_prime;
}
for (size_t i = 1; i < s.length(); ++i) {
hash *= h_prime;
hash += s[i];
HH.push_back(hash);
}
}
inline long long gcd(long long x, long long y) {
while (y) {
x %= y;
swap(x, y);
}
return x;
}
void init_primes(long long maxn) {
vector<bool> np(maxn, false);
np[0] = np[1] = true;
for (int i = 2; i * i < maxn; ++i)
if (!np[i]) {
for (int j = i * i; j < maxn; j += i) np[j] = true;
primes.push_back(i);
}
}
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b /= 2;
}
return res;
}
long long to2(vector<long long>& a) {
long long k = 1;
long long ans = 0;
for (int i = 0; i < a.size(); ++i) {
ans += k * a[i];
k *= 2;
}
return ans;
}
vector<long long> c1(30, 0), c2(30, 0);
long long get(long long a, long long b) {
a += to2(c1);
b += to2(c2);
int ans;
cout << "? " << a << ' ' << b << endl;
cin >> ans;
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
vector<long long> a(30, 0), b(30, 0);
bool f = true;
int used = -1;
for (int i = 29; i >= 0; --i) {
int ans1, ans2;
ans1 = get(1 << i, 0);
ans2 = get(0, 1 << i);
if (ans1 != ans2) {
if (ans1 == -1)
a[i] = b[i] = 1;
else
a[i] = b[i] = 0;
} else {
if (ans1 == 0) {
int ans3 = get(0, 0);
if (ans3 == 1) {
a[i] = 1;
b[i] = 0;
} else {
a[i] = 0;
b[i] = 1;
}
}
if (used == -1) {
int ans3 = get(0, 0);
if (ans3 == 1) {
a[i] = 1;
b[i] = 0;
} else {
a[i] = 0;
b[i] = 1;
}
used = 1;
} else if (f) {
a[i] = 1;
b[i] = 0;
} else {
a[i] = 0;
b[i] = 1;
}
if (ans1 == 1)
f = true;
else
f = false;
}
c1[i] = a[i];
c2[i] = b[i];
}
cout << "! " << to2(a) << ' ' << to2(b) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const long long inf9 = 1e9, inf18 = 1e18, inf6 = 1e6, inf14 = 1e14;
const long long mod7 = inf9 + 7, mod9 = inf9 + 9;
const long long maxn = 62;
int a = 0, b = 0;
int cnt = 0;
bool help = false;
void equal(int x) {
help = true;
if (x < 0) return;
assert(cnt <= 61);
for (int i = x; i >= 0; i--) {
int x = a + (1 << i);
int y = b;
int res;
cout << "? " << x << " " << y << endl;
cout.flush();
cin >> res;
cnt++;
if (res == -1) {
a += (1 << i);
b += (1 << i);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int res = 1, great = 0;
cout << "? 0 0" << endl;
cout.flush();
cin >> res;
cnt++;
if (res == 0) equal(29);
if (res == -1) great = 1;
if (res != 0) {
for (int i = 29; i >= 0; i--) {
assert(help == false);
assert(cnt <= 60);
int x = 1 << i;
int y = 0, res1, res2;
x += a;
y += b;
cout << "? " << x << " " << y << endl;
cout.flush();
cin >> res2;
cnt++;
x = a;
y = (1 << i) + b;
cout << "? " << x << " " << y << endl;
cout.flush();
cin >> res1;
cnt++;
if (great == 0) {
if (res1 == 1 && res2 == -1) {
a += (1 << i);
b += (1 << i);
}
if (res1 == 0 && res2 == 0) {
a += (1 << i);
equal(i - 1);
break;
}
if (res1 == 1 && res1 == res2) {
a += (1 << i);
great = 0;
}
if (res1 == -1 && res1 == res2) {
a += (1 << i);
great = 1;
}
} else {
if (res1 == 1 && res2 == -1) {
a += (1 << i);
b += (1 << i);
}
if (res1 == 0 && res2 == 0) {
b += (1 << i);
equal(i - 1);
break;
}
if (res1 == 1 && res1 == res2) {
b += (1 << i);
great = 0;
}
if (res1 == -1 && res1 == res2) {
b += (1 << i);
great = 1;
}
}
}
}
cout << "! " << a << " " << b << endl;
cout.flush();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int dxK[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dyK[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long n;
long long resp, resp1, resp2;
int main(int argc, char const *argv[]) {
cout.flush();
int A = 0, B = 0;
cout << "? " << 0 << " " << 0 << endl;
cin >> resp;
int greater = 0;
if (resp == 1)
greater = 1;
else
greater = 2;
for (int i = 29; i >= 0; --i) {
int k = 1 << i;
cout << "? " << (A ^ k) << " " << B << endl;
cin >> resp1;
cout << "? " << A << " " << (B ^ k) << endl;
cin >> resp2;
if (resp2 != resp1) {
if (resp2 == 1) {
A ^= (1 << i);
B ^= (1 << i);
}
} else {
if (greater == 1)
A ^= (1 << i);
else
B ^= (1 << i);
if (resp1 == 1)
greater = 1;
else
greater = 2;
}
}
cout << "! " << A << " " << B << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gen(vector<int> &v) {
int ret = 0, cur = 1 << 29;
for (int x : v) {
ret += x * cur;
cur /= 2;
}
return ret;
}
vector<int> complete(const vector<int> &v) {
vector<int> ret = v;
while (ret.size() < 30) ret.emplace_back(0);
return ret;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<int> a, b;
cout << "? " << gen(a) << " " << gen(b) << endl;
int tot_eq;
cin >> tot_eq;
for (int i = 29; i >= 0; i--) {
vector<int> c, d;
c = a;
d = b;
c.emplace_back(1);
d.emplace_back(1);
c = complete(c);
d = complete(d);
cout << "? " << gen(c) << " " << gen(d) << endl;
int x;
cin >> x;
if (x == tot_eq) {
c = a;
d = b;
c.emplace_back(1);
d.emplace_back(0);
c = complete(c);
d = complete(d);
cout << "? " << gen(c) << " " << gen(d) << endl;
int y;
cin >> y;
if (y == 1) {
a.emplace_back(0);
b.emplace_back(0);
} else {
a.emplace_back(1);
b.emplace_back(1);
}
} else {
if (x == 1) {
a.emplace_back(0);
b.emplace_back(1);
} else if (x == -1) {
a.emplace_back(1);
b.emplace_back(0);
} else
assert(0);
cout << "? " << gen(a) << " " << gen(b) << endl;
cin >> tot_eq;
}
}
cout << "! " << gen(a) << " " << gen(b) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 100100, SQ = 330, LG = 25, inf = 1e17;
long long n, m, t, k, x, y, z, w, a, b;
char c = '?';
void get() {
cout << endl;
cin >> x;
if (x == -2) exit(0);
}
void solve(int k, int bit) {
if (bit == -1) return;
long long ax = a, bx = b;
ax += (1 << bit);
bx += (1 << bit);
cout << c << ' ' << ax << ' ' << bx;
get();
if (x == k) {
ax = a;
bx = b;
ax += (1 << bit);
cout << c << ' ' << ax << ' ' << bx;
get();
if (x == -1) {
a += (1 << bit);
b += (1 << bit);
}
solve(k, bit - 1);
return;
} else {
if (k == 1)
a += (1 << bit);
else
b += (1 << bit);
ax = a;
bx = b;
cout << c << ' ' << ax << ' ' << bx;
get();
solve(x, bit - 1);
return;
}
}
int main() {
cout << c << ' ' << 0 << ' ' << 0;
get();
solve(x, 29);
cout << "! " << a << ' ' << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
int ATTENTION() {
http:
return 0;
}
using namespace std;
const int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
if (a < 0) return gcd(-a, b);
if (b < 0) return gcd(a, -b);
if (a < b) return gcd(b, a);
if (b == 0) return a;
return gcd(b, a % b);
}
long long qpow(long long a, long long n, long long mod) {
a %= mod;
long long ans = 1LL;
while (n) {
if (n & 1) ans = (ans * a % mod);
a = (a * a % mod);
n >>= 1;
}
return ans;
}
inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); }
template <typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
DST[s] = SRC[s];
for (int i = 1; i < N; i++) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() {
int x;
cin >> x;
return x;
}
inline void tic() {}
inline void toc() {}
const int maxn = 1;
int ask(long long c, long long d) {
cout << "? " << c << " " << d << endl;
int resp = -2;
cin >> resp;
if (resp == -2) exit(0);
return resp;
}
void output(long long a, long long b) { cout << "! " << a << " " << b << endl; }
int a[33], b[33];
void set_bit(long long& x, int pos, int val) {
if (val == 0) {
x = (~(1LL << pos)) & x;
} else {
x = x | (1LL << pos);
}
}
void solve() {
long long mask_a = 0, mask_b = 0;
int last_cmp = ask(mask_a, mask_b);
for (int i = 29; i >= 0; i--) {
if (last_cmp == -1) {
set_bit(mask_a, i, 1);
set_bit(mask_b, i, 1);
int tmp = ask(mask_a, mask_b);
if (tmp == 1) {
a[i] = 0;
b[i] = 1;
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 1);
last_cmp = ask(mask_a, mask_b);
} else {
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 1);
tmp = ask(mask_a, mask_b);
if (tmp < 0) {
a[i] = b[i] = 0;
} else {
a[i] = b[i] = 1;
}
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 0);
}
} else if (last_cmp == 1) {
set_bit(mask_a, i, 1);
set_bit(mask_b, i, 1);
int tmp = ask(mask_a, mask_b);
if (tmp == -1) {
a[i] = 1;
b[i] = 0;
set_bit(mask_a, i, 1);
set_bit(mask_b, i, 0);
last_cmp = ask(mask_a, mask_b);
} else {
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 1);
tmp = ask(mask_a, mask_b);
if (tmp < 0) {
a[i] = b[i] = 0;
} else {
a[i] = b[i] = 1;
}
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 0);
}
} else if (last_cmp == 0) {
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 1);
int tmp = ask(mask_a, mask_b);
if (tmp < 0) {
a[i] = b[i] = 0;
} else {
a[i] = b[i] = 1;
}
set_bit(mask_a, i, 0);
set_bit(mask_b, i, 0);
}
}
}
int main() {
ios::sync_with_stdio(0);
solve();
long long ra = 0, rb = 0;
for (int i = 0; i < 30; i++) {
ra |= ((long long)a[i] << i);
rb |= ((long long)b[i] << i);
}
output(ra, rb);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline long long power(long long a, long long b) {
long long x = 1;
a = a % 1000000007ULL;
while (b) {
if (b & 1) x = (x * a) % 1000000007ULL;
a = (a * a) % 1000000007ULL;
b >>= 1;
}
return x;
}
inline long long inv(long long a) { return power(a, 1000000007ULL - 2); }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
const int N = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
int a = 0, b = 0, c = 0, d = 0;
int dir = 0, tmp;
cout << "? 0 0" << endl;
fflush(stdout);
int res;
cin >> dir;
fflush(stdout);
int i = 29;
while (i > -1) {
if (dir == 0) break;
tmp = 1 << i;
c = tmp | a;
d = tmp | b;
cout << "? " << c << " " << d << endl;
fflush(stdout);
cin >> res;
fflush(stdout);
if (res != dir) {
if (dir == 1)
a |= tmp;
else
b |= tmp;
cout << "? " << a << " " << b << endl;
fflush(stdout);
cin >> dir;
fflush(stdout);
} else {
c = tmp | a;
d = b;
cout << "? " << c << " " << d << endl;
fflush(stdout);
cin >> res;
fflush(stdout);
if (res == -1) {
a |= tmp;
b |= tmp;
}
}
i--;
}
fflush(stdout);
while (i > -1) {
tmp = 1 << i;
c = tmp | a;
d = b;
cout << "? " << c << " " << d << endl;
fflush(stdout);
cin >> res;
fflush(stdout);
if (res == -1) {
a |= tmp;
b |= tmp;
}
i--;
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int query(int a, int b) {
cout << "? " << a << " " << b << endl;
fflush(stdout);
int tmp;
cin >> tmp;
return tmp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int flag = query(0, 0);
int a = 0, b = 0;
int tmp;
for (int i = 29; i >= 0; i--) {
if (flag == 0) {
tmp = query(a | (1 << i), b);
if (tmp == -1) {
a |= (1 << i);
b |= (1 << i);
}
} else if (flag == 1) {
tmp = query(a | (1 << i), b | (1 << i));
if (tmp == -1) {
a |= (1 << i);
flag = query(a, b);
} else {
tmp = query(a | (1 << i), b);
if (tmp == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
} else {
tmp = query(a | (1 << i), b | (1 << i));
if (tmp == 1) {
b |= (1 << i);
flag = query(a, b);
} else {
tmp = query(a | (1 << i), b);
if (tmp == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
}
}
cout << "! " << a << " " << b << endl;
fflush(stdout);
}
|
#include <bits/stdc++.h>
int main() {
int a = 0, b = 0;
int ck = -2;
for (int i = 29; i >= 0; i--) {
int k1, k2;
if (ck != -2)
k1 = ck;
else {
printf("? %d %d\n", a, b);
fflush(stdout);
scanf("%d", &k1);
}
printf("? %d %d\n", a + (1 << i), b + (1 << i));
fflush(stdout);
scanf("%d", &k2);
if (k1 == k2) {
int k3;
printf("? %d %d\n", a + (1 << i), b);
fflush(stdout);
scanf("%d", &k3);
if (k3 == -1) {
a += (1 << i);
b += (1 << i);
}
ck = k1;
} else {
if (k1 > 0) {
a += (1 << i);
} else {
b += (1 << i);
}
ck = -2;
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
cout << a;
cout << endl;
}
template <class A, class B>
void pr(A a, B b) {
cout << a << ' ';
pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
cout << a << ' ';
pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
cout << a << ' ';
pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
for (long long i = (long long)(0); i < (long long)(n); i++) {
if (i) cout << ' ';
cout << a[i];
}
cout << endl;
}
long long check(long long n, long long m, long long x, long long y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
dy[4] = {0, 1, 0, -1};
void Main() {
long long x = 0, y = 0, a, b, c;
pr('?', x, y);
cin >> a;
for (long long i = (long long)(30) - 1; i >= 0; i--) {
pr('?', x | (1 << i), y);
cin >> b;
if (!a) {
if (b < 0) {
x |= 1 << i;
y |= 1 << i;
}
} else if (a > 0) {
if (!b) {
x |= 1 << i;
a = b;
} else if (b < 0) {
pr('?', x, y | (1 << i));
cin >> c;
x |= 1 << i;
if (b != c)
y |= 1 << i;
else
a = b;
} else {
pr('?', x, y | (1 << i));
cin >> c;
if (b == c) {
x |= 1 << i;
a = b;
}
}
} else {
if (!b) {
y |= 1 << i;
a = b;
} else if (b > 0) {
pr('?', x, y | (1 << i));
cin >> c;
if (b == c) {
y |= 1 << i;
a = c;
}
} else {
pr('?', x, y | (1 << i));
cin >> c;
y |= 1 << i;
if (b != c)
x |= 1 << i;
else
a = c;
}
}
}
pr('!', x, y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
Main();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Pow[35];
int main() {
int a = 0, b = 0, x, y, i, how;
Pow[0] = 1;
for (i = 1; i <= 29; i++) Pow[i] = Pow[i - 1] * 2;
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &how);
for (i = 29; i >= 0; i--) {
printf("? %d %d\n", a + Pow[i], b);
fflush(stdout);
scanf("%d", &x);
printf("? %d %d\n", a, b + Pow[i]);
fflush(stdout);
scanf("%d", &y);
if (x > y) {
a += 0;
b += 0;
} else if (x < y) {
a += Pow[i];
b += Pow[i];
} else {
if (how == 1)
a += Pow[i];
else
b += Pow[i];
how = x;
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long a1 = 0, b1 = 0, q;
cout << '?' << ' ' << 0 << ' ' << 0 << endl;
cin >> q;
if (q == 0) {
for (long long i = 29; i >= 0; i--) {
cout << '?' << ' ' << (1ll << i) << ' ' << 0 << endl;
cin >> q;
if (q == -1) {
a1 |= (1ll << i);
b1 |= (1ll << i);
}
}
cout << '!' << ' ' << a1 << ' ' << b1 << endl;
return 0;
} else {
long long last = q, g1 = 0, g2 = 0;
for (long long i = 29; i >= 0; i--) {
if (last == 0) {
cout << '?' << ' ' << (g1 | (1ll << i)) << ' ' << g2 << endl;
cin >> q;
if (q == -1) {
a1 |= (1ll << i);
b1 |= (1ll << i);
}
continue;
}
cout << '?' << ' ' << (g1 | (1ll << i)) << ' ' << (g2 | (1ll << i))
<< endl;
cin >> q;
if (q != last) {
if (last == 1) {
a1 |= (1ll << i);
g2 |= (1ll << i);
cout << '?' << ' ' << g1 << ' ' << (g2 | (1ll << i)) << endl;
cin >> q;
last = q;
} else if (last == -1) {
b1 |= (1ll << i);
g1 |= (1ll << i);
cout << '?' << ' ' << (g1 | (1ll << i)) << ' ' << g2 << endl;
cin >> q;
last = q;
}
} else if (q == 1) {
cout << '?' << ' ' << g1 << ' ' << (g2 | (1ll << i)) << endl;
cin >> q;
if (q == 1) {
a1 |= (1ll << i);
b1 |= (1ll << i);
}
} else if (q == -1) {
cout << '?' << ' ' << (g1 | (1ll << i)) << ' ' << g2 << endl;
cin >> q;
if (q == -1) {
a1 |= (1ll << i);
b1 |= (1ll << i);
}
}
}
cout << '!' << ' ' << a1 << ' ' << b1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int a, int b) {
printf("? %d %d\n", a, b);
fflush(stdout);
int flg;
scanf("%d", &flg);
return flg;
}
int ans_a = 0, ans_b = 0, a0 = 0, b0 = 0;
int seta(int mask) {
ans_a |= mask;
a0 |= mask;
}
int setb(int mask) {
ans_b |= mask;
b0 |= mask;
}
void f(int mask, int w) {
if (mask == 0) {
printf("! %d %d\n", ans_a, ans_b);
fflush(stdout);
return;
}
if (w == 0) {
int x = ask(a0 | mask, b0);
if (x == -1) {
seta(mask);
setb(mask);
}
f(mask >> 1, 0);
} else {
int x = ask(a0 | mask, b0);
int y = ask(a0, b0 | mask);
if (w == 1) {
if (x * y == -1) {
if (x == -1) {
seta(mask);
setb(mask);
}
f(mask >> 1, w);
} else {
seta(mask);
f(mask >> 1, x);
}
} else {
if (x * y == -1) {
if (x == -1) {
seta(mask);
setb(mask);
}
f(mask >> 1, w);
} else {
setb(mask);
f(mask >> 1, y);
}
}
}
return;
}
int main() {
f(1 << 29, ask(0, 0));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
auto ask = [](long long c, long long d) {
cout << "? " << c << " " << d << endl;
long long x;
cin >> x;
return x;
};
long long ans1 = 0, ans2 = 0;
long long big = ask(0, 0);
for (long long i = 29; i >= 0; i--) {
long long z1 = ask(ans1 ^ (1LL << i), ans2);
long long z2 = ask(ans1, ans2 ^ (1LL << i));
if (z1 == z2) {
if (big == 1) {
ans1 ^= (1LL << i);
} else {
ans2 ^= (1LL << i);
}
big = z1;
} else {
if (z2 == 1) {
ans1 ^= (1LL << i);
ans2 ^= (1LL << i);
}
}
}
cout << "! " << ans1 << " " << ans2 << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cout << "? 0 0\n";
cin >> x;
int a = 0, b = 0;
int c = 0, d = 0;
if (x == 0) {
for (int i = 29; i >= 0; --i) {
cout << "? " << (a ^ (1 << i)) << ' ' << b << "\n";
cin >> x;
if (x == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
cout << "! " << a << ' ' << b;
} else {
int y;
int q = x;
for (int i = 29; i >= 0; --i) {
if (q == 1) {
cout << "? " << a << ' ' << (b ^ (1 << i)) << "\n";
cin >> x;
cout << "? " << (a ^ (1 << i)) << ' ' << (b ^ (1 << i)) << "\n";
cin >> y;
if (x == -1) {
if (y == -1) {
q = -1;
a ^= (1 << i);
}
} else if (x == 1) {
if (y == -1) {
a ^= (1 << i);
} else if (y == 1) {
a ^= (1 << i);
b ^= (1 << i);
}
} else {
a ^= (1 << i);
q = 0;
}
} else if (q == 0) {
cout << "? " << a << ' ' << (b ^ (1 << i)) << "\n";
cin >> x;
if (x == 1) {
a ^= (1 << i);
b ^= (1 << i);
}
} else {
cout << "? " << (a ^ (1 << i)) << ' ' << b << "\n";
cin >> x;
cout << "? " << (a ^ (1 << i)) << ' ' << (b ^ (1 << i)) << "\n";
cin >> y;
if (x == 1) {
if (y == 1) {
q = 1;
b ^= (1 << i);
}
} else if (x == -1) {
if (y == 1) {
b ^= (1 << i);
} else if (y == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
} else {
b ^= (1 << i);
q = 0;
}
}
}
cout << "! " << a << ' ' << b;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int ans;
int a = 0, b = 0, l;
int z1, z2;
int f = 0;
int main() {
cout << "? 0 0" << endl;
cin >> ans;
if (ans == 1)
f = 1;
else if (ans == -1)
f = 2;
l++;
for (int i = 29; i >= 0; i--) {
cout << "? " << a + (1 << i) << " " << b << endl;
l++;
l++;
cin >> z1;
l++;
cout << "? " << a << " " << b + (1 << i) << endl;
l++;
cin >> z2;
l++;
if (z1 == -1 && z2 == 1) {
a += (1 << i);
b += (1 << i);
l++;
} else if (z1 == 1 && z2 == -1) {
continue;
} else if (f == 1) {
a += (1 << i);
if (z1 == -1)
f = 2;
else if (z1 == 1)
f = 1;
else
f = 0;
l++;
} else if (f == 2) {
b += (1 << i);
if (z2 == 1)
f = 1;
else if (z2 == -1)
f = 2;
else
f = 0;
l++;
}
l++;
}
cout << "! " << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
long long ask(long long c, long long d) {
long long ret;
cout << "? " << c << " " << d << endl;
cin >> ret;
return ret;
}
void print(long long a, long long b) {
cout << "! " << a << " " << b << endl;
exit(0);
}
void sol(long long is, long long a, long long b, long long id) {
if (id == -1) print(a, b);
long long cur = 0;
if (is == 1) {
cur = ask(a | (1 << id), b | (1 << id));
if (cur == 1) {
if (ask(a, b | (1 << id)) == 1) {
a |= (1 << id);
b |= (1 << id);
} else {
}
sol(1, a, b, id - 1);
} else {
a |= (1 << id);
sol(ask(a, b), a, b, id - 1);
}
} else if (is == 0) {
for (long long i = id; i >= 0; i--) {
if (ask(a | (1 << i), b) == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
print(a, b);
} else {
cur = ask(a | (1 << id), b | (1 << id));
if (cur == -1) {
if (ask(a | (1 << id), b) == 1) {
} else {
a |= (1 << id);
b |= (1 << id);
}
sol(-1, a, b, id - 1);
} else {
b |= (1 << id);
sol(ask(a, b), a, b, id - 1);
}
}
}
signed main() {
if (ask(0, 0) == 0) {
long long res = 0;
for (long long i = 0; i < 30; i++) {
if (ask(1 << i, 0) == -1) {
res |= (1 << i);
}
}
print(res, res);
} else {
sol(ask(0, 0), 0, 0, 29);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<ld, ld>;
int __intend = 0;
void nextIntend() { __intend++; }
void prevIntend() { __intend--; }
string getIntend() {
string r;
for (int i = 0; i < __intend; ++i) {
r += '\t';
}
return r;
}
template <typename T>
void print(const char s[], bool intend, T& v) {
if (intend) cout << getIntend();
cout << s << " = " << v << endl;
}
template <typename T, typename... TA>
void print(const char s[], bool intend, T& v, TA&... args) {
if (intend) cout << getIntend();
while (*s != ',') {
if (*s != ' ') cout << *s;
s++;
}
while (*s == ',' || *s == ' ') s++;
cout << " = " << v << " | ";
print(s, false, args...);
}
int query(int c, int d) {
cout << "? " << c << ' ' << d << endl;
cout.flush();
int ans;
cin >> ans;
return ans;
}
void answer(int a, int b) {
cout << "! " << a << ' ' << b << endl;
cout.flush();
}
int a, b;
void solve() {
int a = 0;
int b = 0;
int st = query(a, b);
for (int bit = 1 << 29; bit > 0; bit >>= 1) {
int q1, q2;
switch (st) {
case 0:
q1 = query(a | bit, b);
if (q1 < 0) {
a |= bit;
b |= bit;
}
break;
case 1:
q1 = query(a | bit, b);
if (q1 <= 0) {
a |= bit;
st = q1;
}
if (!q1) break;
q2 = query(a, b | bit);
if (q1 <= 0 && q2 <= 0) {
st = q1;
}
if (q1 < 0 && q2 > 0) {
b |= bit;
st = q2;
}
if (q1 > 0 && q2 < 0) {
st = 1;
}
if (q1 > 0 && q2 >= 0) {
a |= bit;
st = 1;
}
break;
case -1:
q1 = -query(a, b | bit);
if (q1 <= 0) {
b |= bit;
st = -q1;
}
if (!q1) break;
q2 = -query(a | bit, b);
if (q1 <= 0 && q2 < 0) {
st = -q1;
}
if (q1 <= 0 && q2 > 0) {
a |= bit;
st = -q2;
}
if (q1 > 0 && q2 < 0) {
st = -1;
}
if (q1 > 0 && q2 >= 0) {
b |= bit;
st = -1;
}
}
}
answer(a, b);
}
int squery(int c, int d) {
if ((a ^ c) == (b ^ d)) return 0;
if ((a ^ c) > (b ^ d))
return 1;
else
return -1;
}
pii ssolve() {
int a = 0;
int b = 0;
int st = squery(a, b);
for (int bit = 1 << 29; bit > 0; bit >>= 1) {
int q1, q2;
switch (st) {
case 0:
q1 = squery(a | bit, b);
if (q1 < 0) {
a |= bit;
b |= bit;
}
break;
case 1:
q1 = squery(a | bit, b);
if (q1 <= 0) {
a |= bit;
st = q1;
}
if (!q1) break;
q2 = squery(a, b | bit);
if (q1 <= 0 && q2 <= 0) {
st = q1;
}
if (q1 < 0 && q2 > 0) {
b |= bit;
st = q2;
}
if (q1 > 0 && q2 < 0) {
st = 1;
}
if (q1 > 0 && q2 >= 0) {
a |= bit;
st = 1;
}
break;
case -1:
q1 = -squery(a, b | bit);
if (q1 <= 0) {
b |= bit;
st = -q1;
}
if (!q1) break;
q2 = -squery(a | bit, b);
if (q1 <= 0 && q2 < 0) {
st = -q1;
}
if (q1 <= 0 && q2 > 0) {
a |= bit;
st = -q2;
}
if (q1 > 0 && q2 < 0) {
st = -1;
}
if (q1 > 0 && q2 >= 0) {
b |= bit;
st = -1;
}
}
}
return {a, b};
}
const bool fastIO = false;
const bool withTest = false;
const bool fileIO = false;
const bool stress = false;
int main() {
srand(time(0));
if (fileIO) {
freopen(
"file"
".in",
"r", stdin);
freopen(
"file"
".out",
"w", stdout);
}
if (fastIO) {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
if (withTest) {
int t;
cin >> t;
while (t--) solve();
} else if (!stress)
solve();
else {
while (true) {
a = rand() % 1000;
b = rand() % 1000;
if (0)
cout << "a"
<< " = " << a << " | "
<< "b"
<< " = " << b << " | " << endl;
int ta, tb;
tie(ta, tb) = ssolve();
if (ta != a || tb != b) {
cout << "ta"
<< " = " << ta << " | "
<< "tb"
<< " = " << tb << " | " << endl;
cout << "error" << endl;
break;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int a[maxn];
int query(int a, int b) {
printf("? %d %d\n", a, b);
int tmp;
cin >> tmp;
return tmp;
}
int main() {
int n;
int abig = query(0, 0);
long long a = 0, b = 0;
for (int i = 29; i >= 0; i--) {
int x = query(a ^ (1 << i), b), y = query(a, b ^ (1 << i));
if (x == y) {
if (abig == 1) {
a ^= (1 << i);
} else
b ^= (1 << i);
abig = x;
} else {
if (x == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
}
cout << '!' << " " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d) {
printf("? %d %d\n", c, d);
int ans;
cin >> ans;
return ans;
}
int main() {
cout.flush();
int a = 0, b = 0, big = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
if (f == s) {
if (big == 1)
a ^= (1 << i);
else
b ^= (1 << i);
big = f;
} else if (f == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
}
printf("! %d %d\n", a, b);
return 0;
}
|
#include <bits/stdc++.h>
long long int mod = 1000000000 + 7;
long long int inf = (long long int)(5e18);
using namespace std;
mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count());
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a = 0, b = 0;
int cmp;
cout << "? 0 0" << endl;
cin >> cmp;
for (int i = 29; i >= 0; i--) {
cout << "? " << (1 << i) + a << " " << (1 << i) + b << endl;
int x;
cin >> x;
if (x == 0) {
cout << "? " << (1 << i) + a << " " << b << endl;
cin >> x;
if (x == -1) {
a ^= (1 << i);
b ^= (1 << i);
}
} else if (x == 1) {
if (cmp == -1) {
b ^= (1 << i);
cout << "? " << a << " " << b << endl;
cin >> cmp;
} else {
cout << "? " << a + (1 << i) << " " << b << endl;
cin >> x;
if (x == -1) a ^= (1 << i), b ^= (1 << i);
}
} else {
if (cmp == 1) {
a ^= (1 << i);
cout << "? " << a << " " << b << endl;
cin >> cmp;
} else {
cout << "? " << a << " " << b + (1 << i) << endl;
cin >> x;
if (x == 1) a ^= (1 << i), b ^= (1 << i);
}
}
}
cout << "! " << a << " " << b << endl;
}
|
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int maxn = 2e4 + 10;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const double eps = 1e-7;
using namespace std;
int a[50], b[50], ans1, ans2, pre, lastt;
int main() {
printf("? %d %d\n", 0, 0);
fflush(stdout);
scanf("%d", &lastt);
pre = 0;
for (int i = 29; i >= 0; --i) {
int op1, op2, tmp = 1 << i;
printf("? %d %d\n", pre + tmp, 0);
fflush(stdout);
scanf("%d", &op1);
printf("? %d %d\n", pre, tmp);
fflush(stdout);
scanf("%d", &op2);
if (op1 != op2) {
if (op1 == -1)
a[i] = 1, b[i] = 1;
else
a[i] = 0, b[i] = 0;
} else {
if (lastt == 1)
a[i] = 1, b[i] = 0;
else
a[i] = 0, b[i] = 1;
lastt = op1;
pre += tmp;
}
}
for (int i = 29; i >= 0; --i) {
ans1 += a[i] * (1 << i);
ans2 += b[i] * (1 << i);
}
printf("! %d %d\n", ans1, ans2);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
cout << "? " << 0 << ' ' << 0 << endl;
cout.flush();
int sgn;
cin >> sgn;
;
int x = 0, y = 0;
for (int i = 29; i >= 0; i--) {
if (sgn == 0) {
int xx = x ^ (1 << i), yy = y;
cout << "? " << xx << ' ' << yy << endl;
cout.flush();
int aux;
cin >> aux;
;
if (aux == -1) x ^= (1 << i), y ^= (1 << i);
} else {
int xx = x ^ (1 << i), yy = y ^ (1 << i);
cout << "? " << xx << ' ' << yy << endl;
cout.flush();
int aux;
cin >> aux;
;
if (aux == sgn) {
xx = x, yy = y;
if (aux == -1)
yy ^= (1 << i);
else
xx ^= (1 << i);
cout << "? " << xx << ' ' << yy << endl;
cout.flush();
int rs;
cin >> rs;
;
if (rs != sgn) x ^= (1 << i), y ^= (1 << i);
} else {
if (sgn == -1)
y ^= (1 << i);
else
x ^= (1 << i);
cout << "? " << x << ' ' << y << endl;
cout.flush();
int rs;
cin >> rs;
;
sgn = rs;
}
}
}
cout << "! " << x << ' ' << y << endl;
cout.flush();
}
|
#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ask(int c, int d) {
cout << "? " << c << " " << d << endl;
cout.flush();
int scan;
cin >> scan;
return scan;
}
int main() {
int a = 0, b = 0;
int g = ask(0, 0);
for (int i = 29; i >= 0; i--) {
int f = ask(a ^ (1 << i), b);
int s = ask(a, b ^ (1 << i));
if (f == s) {
if (g == 1)
a |= 1 << i;
else
b |= 1 << i;
g = f;
} else if (f == -1) {
a |= (1 << i);
b |= 1 << i;
}
}
cout << "! " << a << " " << b;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.