#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b)
using namespace std;
#define INF 1000000000000000000
#define lld long double
#define int long long int
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...)
#define vprint(...)
#endif
namespace solver {
int n, cur, cnt;
const int key = 999999999999999999;
int query(int x) {
cout << "? " << x << endl;
int x; cin >> x;
// int ans = abs(cur - x) >= key;
cur = x, cnt ++;
return ans;
}
void solve(int _n) {
n = _n, cnt = 0, cur = 0;
int x = 0, L = 0, R = n, yes = 0;
while(R - L > 1) {
int mid = (L + R) / 2;
x += (yes ? -1 : 1) * mid;
yes ^= 1, cur = min(cur, x);
L = mid;
}
L = 0, R = n;
cur = 1 - cur, yes = 0;
while(R - L > 1) {
int mid = (L + R) / 2;
int id = (yes ? -1 : 1);
bool ans = query(cur + id * mid);
yes ^= 1;
if(ans) R = mid;
else L = mid;
}
print(cnt);
cout << "= " << R << endl;
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
solve(n);
return 0;
}
Compilation message
Colors.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
Colors.cpp:21:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
Colors.cpp:21:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
Colors.cpp: In function 'long long int solver::query(long long int)':
Colors.cpp:33:7: error: declaration of 'long long int x' shadows a parameter
33 | int x; cin >> x;
| ^
Colors.cpp:31:16: note: 'long long int x' previously declared here
31 | int query(int x) {
| ^
Colors.cpp:36:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
36 | return ans;
| ^~~
| abs