0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

D - Fixed Point Guessing

https://codeforces.com/contest/1698/submission/162148239
This commit is contained in:
Baoshuo Ren 2022-06-29 00:38:01 +08:00
parent 251274fc67
commit 1a0a51962d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

44
Codeforces/1698/D/D.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int t, n, ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
ans = 0;
cin >> n;
int l = 1, r = n;
while (l <= r) {
int mid = l + r >> 1;
cout << "? " << 1 << ' ' << mid << endl;
int cnt = 0;
for (int i = 1, x; i <= mid; i++) {
cin >> x;
if (x <= mid) cnt++;
}
if (cnt & 1) {
r = mid - 1;
ans = mid;
} else {
l = mid + 1;
}
}
cout << "! " << ans << endl;
}
return 0;
}