#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
long n;
set<long> vis;
bool valid(long x) {
return 1 <= x && x <= n && !vis.count(x);
}
long mmid() {
long lg = __lg(n);
if ((1 << lg) == n) {
return (1 + n) / 2;
}
return n - (1 << lg);
}
long dfs(long l, long r) {
if (l == r) {
return 1;
}
long mid = (l + r) / 2;
long x = dfs(mid + 1, r);
if (valid(x - mid)) {
return x - mid;
} else {
return x + mid;
}
}
long query(long x) {
dbg(x);
assert(valid(x));
vis.insert(x);
cout << "? " << x << endl;
cin >> x;
return x;
}
bool check(long l, long r, long prev) {
if (l == r) {
return true;
}
long mid = (l + r) / 2;
long nxt = prev + mid;
if (!valid(nxt)) {
nxt = prev - mid;
if (!valid(nxt)) {
return false;
}
}
vis.insert(nxt);
bool ans = check(l, mid, nxt) && check(mid + 1, r, nxt);
vis.erase(nxt);
return ans;
}
void solve(long l, long r, long prev) {
if (l == r) {
cout << "= " << l << endl;
return;
}
long mid = (l + r) / 2;
long nxt = prev + mid;
if (!valid(nxt)) {
nxt = prev - mid;
}
if (query(nxt)) {
solve(l, mid, nxt);
} else {
solve(mid + 1, r, nxt);
}
}
void solve() {
cin >> n;
long start = dfs(1, n);
if (n <= long(1e6)) {
for (long i = max(long(1), start - 2); i <= min(n, start + 2); i++) {
if (check(1, n, start)) {
query(start);
solve(1, n, start);
}
}
} else {
query(start);
solve(1, n, start);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
1 ms |
208 KB |
OK (7 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
1 ms |
208 KB |
OK (6 queries) |
5 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
1 ms |
208 KB |
OK (7 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
1 ms |
208 KB |
OK (6 queries) |
5 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
1 ms |
208 KB |
OK (7 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
1 ms |
208 KB |
OK (6 queries) |
5 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
1 ms |
208 KB |
OK (7 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
1 ms |
208 KB |
OK (6 queries) |
5 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
1 ms |
208 KB |
OK (7 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
1 ms |
208 KB |
OK (6 queries) |
5 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
6 |
Halted |
0 ms |
0 KB |
- |