#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> ask(int i);
vector<int> res[200005];
int ans;
int big, nn;
set<int> lol;
vector<int> query(int i){
if(res[i].size() == 2)
return res[i];
if(i == 0)
return vector<int>({0, big});
if(i == nn + 1)
return vector<int>({big, 0});
return ask(i - 1);
}
void find(int l, int r){
if(ans) return;
if(res[l][0] == res[r][0]) return;
auto it = lol.find(l);
while(res[l][0] == res[*it][0]){
l = *it;
it++;
}
it = lol.find(r);
while(res[r][0] == res[*it][0]){
r = *it;
it--;
}
int ll, rr, m = (l + r) >> 1;
res[m] = query(m);
if(res[m][0] + res[m][1] == big){
lol.insert(m);
find(l, m);
find(m, r);
return;
}
if(res[m][0] + res[m][1] == 0){
ans = m;
return;
}
for(rr = m + 1; rr < r; rr++){
res[rr] = query(rr);
if(res[rr][0] + res[rr][1] == big){
lol.insert(rr);
find(rr, r);
break;
}
if(res[rr][0] + res[rr][1] == 0){
ans = rr;
return;
}
}
find(l, rr);
}
int find_best(int n) {
nn = n;
for(int i = 0; i < 500; i++) {
vector<int> res = ask(i);
if(res[0] + res[1] == 0)
return i;
big = max(big, res[0] + res[1]);
}
res[0] = query(0);
res[nn + 1] = query(nn + 1);
lol.insert(0);
lol.insert(nn + 1);
find(0, nn + 1);
return ans - 1;
}
Compilation message
prize.cpp: In function 'void find(int, int)':
prize.cpp:33:8: warning: unused variable 'll' [-Wunused-variable]
int ll, rr, m = (l + r) >> 1;
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
5120 KB |
Output is correct |
5 |
Correct |
9 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
8 ms |
5040 KB |
Output is correct |
9 |
Correct |
11 ms |
4992 KB |
Output is correct |
10 |
Correct |
12 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
Output is correct |
2 |
Correct |
10 ms |
5120 KB |
Output is correct |
3 |
Correct |
14 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
5120 KB |
Output is correct |
5 |
Correct |
13 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
5104 KB |
Output is correct |
7 |
Correct |
11 ms |
4992 KB |
Output is correct |
8 |
Correct |
8 ms |
5016 KB |
Output is correct |
9 |
Correct |
11 ms |
4992 KB |
Output is correct |
10 |
Correct |
10 ms |
4992 KB |
Output is correct |
11 |
Runtime error |
1531 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |