-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF1.cpp
46 lines (38 loc) · 765 Bytes
/
F1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
int query(int l, int r) {
cout << "? " << l << " " << r << endl;
int val;
cin >> val;
return val;
}
void run_cases() {
int n, t;
cin >> n >> t;
// ( ] interval;
int k;
cin >> k;
int r = n;
int l = 0;
while(r > l + 1) {
int m = (r + l) / 2;
int val = query(l + 1, m);
int zeros = m - l - val;
if(k <= zeros) {
r = m;
} else {
k -= zeros;
l = m;
}
}
cout << "! " << r << endl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
// cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}