//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "prize.h"
const int maxn = 2e5+10;
int ans;
set <int> pos;
vector <int> val;
int sum;
set <int> hi;
void solve(int l,int r,int pre,int suf) {
if (l>r) return;
int midl = l+r>>1;
int midr = midl;
vector <int> tmp = {-1,-1};
while (midl>=l) {
tmp = ask(midl);
if (tmp[0]+tmp[1]==sum) break;
if (tmp[0]+tmp[1]==0) {
ans = midl;
return;
}
pos.insert(midl);
midl--;
}
if (midl<l) {
midr++;
while (midr<=r) {
tmp = ask(midr);
if (tmp[0]+tmp[1]==sum) break;
if (tmp[0]+tmp[1]==0) {
ans = midr;
return;
}
pos.insert(midr);
midr++;
}
if (midr>r) return;
if (tmp[1]-suf>0) solve(midr+1,r,tmp[0],suf);
}
else {
if (tmp[0]-pre>0) solve(l,midl-1,pre,tmp[1]);
if (tmp[1]-(midr-midl)-suf>0) solve(midr+1,r,tmp[0]+midr-midl,suf);
}
return;
}
int find_best(int n) {
int ed;
rep(i,0,472) {
vector <int> tmp = ask(i);
if (tmp[0]+tmp[1]==0) return i;
val.pb(tmp[0]+tmp[1]);
hi.insert(val.back());
ed = i;
if (SZ(hi)==4) break;
}
sort(ALL(val));val.erase(unique(ALL(val)),val.end());
sum=val.back();
solve(ed+1,n-1,0,0);
return ans;
}
Compilation message
prize.cpp: In function 'void solve(int, int, int, int)':
prize.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int midl = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
288 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
5 ms |
296 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
292 KB |
Output is correct |
10 |
Correct |
6 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
424 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
288 KB |
Output is correct |
5 |
Correct |
4 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
288 KB |
Output is correct |
7 |
Correct |
4 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
284 KB |
Output is correct |
9 |
Correct |
3 ms |
280 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
9 ms |
308 KB |
Output is correct |
12 |
Correct |
10 ms |
332 KB |
Output is correct |
13 |
Correct |
7 ms |
208 KB |
Output is correct |
14 |
Correct |
15 ms |
304 KB |
Output is correct |
15 |
Correct |
34 ms |
424 KB |
Output is correct |
16 |
Correct |
49 ms |
308 KB |
Output is correct |
17 |
Correct |
4 ms |
296 KB |
Output is correct |
18 |
Correct |
37 ms |
304 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
40 ms |
292 KB |
Output is correct |
21 |
Correct |
52 ms |
416 KB |
Output is correct |
22 |
Correct |
31 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
4 ms |
300 KB |
Output is correct |
25 |
Correct |
39 ms |
304 KB |
Output is correct |
26 |
Correct |
48 ms |
308 KB |
Output is correct |
27 |
Correct |
8 ms |
288 KB |
Output is correct |
28 |
Correct |
25 ms |
308 KB |
Output is correct |
29 |
Correct |
34 ms |
208 KB |
Output is correct |
30 |
Correct |
39 ms |
292 KB |
Output is correct |
31 |
Correct |
6 ms |
208 KB |
Output is correct |
32 |
Correct |
9 ms |
328 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
33 ms |
268 KB |
Output is correct |
35 |
Correct |
7 ms |
208 KB |
Output is correct |
36 |
Correct |
43 ms |
412 KB |
Output is correct |
37 |
Correct |
11 ms |
288 KB |
Output is correct |
38 |
Correct |
6 ms |
208 KB |
Output is correct |
39 |
Correct |
33 ms |
284 KB |
Output is correct |
40 |
Correct |
38 ms |
296 KB |
Output is correct |
41 |
Correct |
65 ms |
208 KB |
Output is correct |
42 |
Correct |
44 ms |
300 KB |
Output is correct |
43 |
Correct |
40 ms |
292 KB |
Output is correct |
44 |
Correct |
39 ms |
296 KB |
Output is correct |
45 |
Correct |
58 ms |
284 KB |
Output is correct |
46 |
Correct |
5 ms |
208 KB |
Output is correct |
47 |
Correct |
37 ms |
292 KB |
Output is correct |
48 |
Correct |
20 ms |
360 KB |
Output is correct |
49 |
Correct |
42 ms |
284 KB |
Output is correct |
50 |
Correct |
58 ms |
288 KB |
Output is correct |
51 |
Correct |
58 ms |
288 KB |
Output is correct |
52 |
Correct |
52 ms |
288 KB |
Output is correct |
53 |
Correct |
5 ms |
328 KB |
Output is correct |
54 |
Correct |
44 ms |
208 KB |
Output is correct |
55 |
Correct |
4 ms |
208 KB |
Output is correct |
56 |
Correct |
51 ms |
284 KB |
Output is correct |
57 |
Correct |
59 ms |
288 KB |
Output is correct |
58 |
Correct |
49 ms |
300 KB |
Output is correct |
59 |
Correct |
29 ms |
420 KB |
Output is correct |
60 |
Correct |
45 ms |
292 KB |
Output is correct |
61 |
Correct |
5 ms |
296 KB |
Output is correct |
62 |
Correct |
4 ms |
304 KB |
Output is correct |
63 |
Correct |
4 ms |
208 KB |
Output is correct |
64 |
Correct |
3 ms |
296 KB |
Output is correct |
65 |
Correct |
5 ms |
288 KB |
Output is correct |
66 |
Correct |
9 ms |
208 KB |
Output is correct |
67 |
Correct |
5 ms |
292 KB |
Output is correct |
68 |
Correct |
5 ms |
208 KB |
Output is correct |
69 |
Correct |
7 ms |
280 KB |
Output is correct |
70 |
Correct |
7 ms |
288 KB |
Output is correct |
71 |
Partially correct |
44 ms |
304 KB |
Partially correct - number of queries: 5231 |
72 |
Correct |
6 ms |
336 KB |
Output is correct |
73 |
Partially correct |
41 ms |
304 KB |
Partially correct - number of queries: 5168 |
74 |
Partially correct |
53 ms |
328 KB |
Partially correct - number of queries: 5195 |
75 |
Correct |
4 ms |
208 KB |
Output is correct |
76 |
Correct |
38 ms |
296 KB |
Output is correct |
77 |
Correct |
44 ms |
304 KB |
Output is correct |
78 |
Correct |
8 ms |
424 KB |
Output is correct |
79 |
Correct |
22 ms |
328 KB |
Output is correct |
80 |
Correct |
45 ms |
308 KB |
Output is correct |
81 |
Correct |
50 ms |
428 KB |
Output is correct |
82 |
Correct |
48 ms |
300 KB |
Output is correct |
83 |
Correct |
5 ms |
208 KB |
Output is correct |
84 |
Correct |
37 ms |
292 KB |
Output is correct |
85 |
Correct |
35 ms |
208 KB |
Output is correct |
86 |
Correct |
5 ms |
208 KB |
Output is correct |
87 |
Correct |
2 ms |
208 KB |
Output is correct |
88 |
Correct |
5 ms |
288 KB |
Output is correct |
89 |
Correct |
3 ms |
208 KB |
Output is correct |
90 |
Correct |
6 ms |
208 KB |
Output is correct |
91 |
Correct |
3 ms |
208 KB |
Output is correct |
92 |
Correct |
6 ms |
300 KB |
Output is correct |
93 |
Correct |
5 ms |
304 KB |
Output is correct |
94 |
Correct |
7 ms |
208 KB |
Output is correct |
95 |
Correct |
9 ms |
208 KB |
Output is correct |
96 |
Correct |
9 ms |
208 KB |
Output is correct |
97 |
Correct |
4 ms |
208 KB |
Output is correct |