#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
vi ev, od;
int n;
bool check(int x, int v) {
if(x == 0) return true;
x *= 2;
x += v;
for(int i=1; i+x-1<=n; i++) {
printf("? %d %d\n", i, i+x-1);
fflush(stdout);
int o;
scd(o);
if(o) return true;
}
return false;
}
int main() {
cin >> n;
int ma = 1;
int lo = 0;
int hi = n/2;
forr(i, 1, n+1) {
ev.pb(i);
od.pb(i);
}
while(lo != hi) {
int mid = (lo + hi+1)/2;
if(check(mid, 0)) {
lo = mid;
}
else hi = mid-1;
}
int v1 = lo;
lo = 0;
hi = (n-1)/2;
while(lo != hi) {
int mid = (lo + hi+1)/2;
if(check(mid, 1)) lo = mid;
else hi = mid-1;
}
printf("! %d\n", max(2*v1, 2*lo+1));
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:55:9: warning: unused variable 'ma' [-Wunused-variable]
55 | int ma = 1;
| ^~
Main.cpp: In function 'void usaco()':
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'bool check(int, int)':
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
Main.cpp:45:9: note: in expansion of macro 'scd'
45 | scd(o);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
492 KB |
Output is correct |
2 |
Correct |
745 ms |
496 KB |
Output is correct |
3 |
Correct |
752 ms |
496 KB |
Output is correct |
4 |
Correct |
541 ms |
496 KB |
Output is correct |
5 |
Correct |
806 ms |
496 KB |
Output is correct |
6 |
Correct |
530 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
332 ms |
504 KB |
Output is correct |
9 |
Correct |
313 ms |
500 KB |
Output is correct |
10 |
Correct |
731 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
492 KB |
Output is correct |
2 |
Correct |
745 ms |
496 KB |
Output is correct |
3 |
Correct |
752 ms |
496 KB |
Output is correct |
4 |
Correct |
541 ms |
496 KB |
Output is correct |
5 |
Correct |
806 ms |
496 KB |
Output is correct |
6 |
Correct |
530 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
332 ms |
504 KB |
Output is correct |
9 |
Correct |
313 ms |
500 KB |
Output is correct |
10 |
Correct |
731 ms |
500 KB |
Output is correct |
11 |
Runtime error |
954 ms |
1144 KB |
Execution killed with signal 13 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
956 ms |
1416 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
492 KB |
Output is correct |
2 |
Correct |
745 ms |
496 KB |
Output is correct |
3 |
Correct |
752 ms |
496 KB |
Output is correct |
4 |
Correct |
541 ms |
496 KB |
Output is correct |
5 |
Correct |
806 ms |
496 KB |
Output is correct |
6 |
Correct |
530 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
332 ms |
504 KB |
Output is correct |
9 |
Correct |
313 ms |
500 KB |
Output is correct |
10 |
Correct |
731 ms |
500 KB |
Output is correct |
11 |
Runtime error |
954 ms |
1144 KB |
Execution killed with signal 13 |
12 |
Halted |
0 ms |
0 KB |
- |