/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int N = 200005;
LL n, ans;
LL last;
unordered_map<LL, int> used;
int get(LL p)
{
assert(!used[p]);
used[p] = 1;
cout << "? " << p << endl;
int res;
cin >> res;
if (last && res && abs(last - p) < ans)
ans = abs(last - p);
last = p;
return res;
}
LL f(LL x)
{
LL i = n - x;
return 1ll + i / 2ll;
}
void solve()
{
last = 0;
used.clear();
cin >> n;
ans = n;
LL l = 1, r = n / 2 - (LL)(n % 2 == 0);
while (l <= r)
{
LL m = (l + r) / 2;
LL a = f(m + m), b = f(m + m) + m + m;
/*if (rand() % 2)
swap(a, b);*/
get(a);
if (get(b))
{
ans = min(m + m, ans);
r = m - 1ll;
}
else
l = m + 1ll;
}
used[last] = 0;
bool fnd = (ans % 1);
if (n > mod)
{
vector<LL> v;
int k = N;
while (k--)
v.push_back((LL)rand() * (LL)rand());
for (LL I = 0; I < v.size() && ans % 2 == 0; I++)
{
LL i = v[I];
if (!used[i] && !used[i + ans - 1ll])
{
used[last] = 1;
LL a = i, b = i + ans - 1ll;
if (b == last)
swap(a, b);
if (a != last)
get(a);
get(b);
fnd = 1;
break;
}
}
}
for (LL i = 1; i + ans - 1ll <= n && ans % 2 == 0; i++)
if (!used[i] && !used[i + ans - 1ll])
{
used[last] = 1;
LL a = i, b = i + ans - 1ll;
if (b == last)
swap(a, b);
if (a != last)
get(a);
get(b);
fnd = 1;
break;
}
cout << "= " << ans << endl;
}
//
int main()
{
fastIO;
int T;
cin >> T;
while (T--)
solve();
return 0;
}
/*
*/
Compilation message
Colors.cpp: In function 'void solve()':
Colors.cpp:92:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (LL I = 0; I < v.size() && ans % 2 == 0; I++)
~~^~~~~~~~~~
Colors.cpp:85:10: warning: variable 'fnd' set but not used [-Wunused-but-set-variable]
bool fnd = (ans % 1);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
384 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
384 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
384 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
384 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
384 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |