#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include "prize.h"
using namespace std;
vector<int> res;
#define Maxn 200010
bool flag[Maxn];
int ans[Maxn][2];
int maxv=0,pos;
int answer;
void Ask(int x){
if(flag[x])return;
flag[x]=true;
res=ask(x);
ans[x][0]=res[0];ans[x][1]=res[1];
}
void solve(int l,int r,int ed,int val){
if(l==r){
Ask(l);
if(ans[l][0]==0&&ans[l][1]==0)answer=l;
return;
}
int mid=(l+r)>>1;
if(ed==-1){
solve(l,mid,ed,mid-l+1);
solve(mid+1,r,ed,r-mid);
return;
}
if(ed<=mid){
if(val-(r-mid))solve(l,mid,ed,val-(r-mid));
solve(mid+1,r,-1,r-mid);
return;
}
int tmp=-1;
for(int i=mid;i>=l;--i){
Ask(i);
if(ans[i][0]+ans[i][1]==maxv){
tmp=i;
break;
}
}
if(tmp==-1){
solve(l,mid,-1,mid-l+1);
if(val-(mid-l+1))solve(mid+1,r,ed,val-(mid-l+1));
return;
}
int now=ans[ed][0]-ans[tmp][0]-(mid-tmp)+r-ed;
if(now)solve(mid+1,r,ed,now);
now=val-now;
if(now)solve(l,mid,tmp,now);
}
int find_best(int n){
srand(time(NULL));
for(register int i=1;i<=100;++i){
int x=1ll*rand()*rand()%n;
Ask(x);
maxv=max(maxv,ans[x][0]+ans[x][1]);
}
int last;
for(register int i=n-1;i>=0;--i){
Ask(i);
if(ans[i][0]==0&&ans[i][1]==0)return i;
if(ans[i][0]+ans[i][1]==maxv){
last=i;
break;
}
}
solve(0,n-1,last,ans[last][0]+ans[last][1]);
return answer;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:64:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
int last;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
920 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
912 KB |
Output is correct |
4 |
Correct |
4 ms |
760 KB |
Output is correct |
5 |
Correct |
5 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
3 ms |
892 KB |
Output is correct |
8 |
Correct |
3 ms |
836 KB |
Output is correct |
9 |
Correct |
4 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
956 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
816 KB |
Output is correct |
4 |
Correct |
4 ms |
920 KB |
Output is correct |
5 |
Correct |
4 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
800 KB |
Output is correct |
8 |
Correct |
4 ms |
896 KB |
Output is correct |
9 |
Correct |
4 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
896 KB |
Output is correct |
11 |
Correct |
8 ms |
1272 KB |
Output is correct |
12 |
Correct |
6 ms |
1272 KB |
Output is correct |
13 |
Correct |
8 ms |
1280 KB |
Output is correct |
14 |
Correct |
13 ms |
432 KB |
Output is correct |
15 |
Correct |
19 ms |
2060 KB |
Output is correct |
16 |
Correct |
19 ms |
2040 KB |
Output is correct |
17 |
Correct |
29 ms |
2036 KB |
Output is correct |
18 |
Correct |
18 ms |
2104 KB |
Output is correct |
19 |
Correct |
23 ms |
2096 KB |
Output is correct |
20 |
Correct |
13 ms |
1224 KB |
Output is correct |
21 |
Correct |
20 ms |
2108 KB |
Output is correct |
22 |
Correct |
16 ms |
2240 KB |
Output is correct |
23 |
Correct |
3 ms |
1096 KB |
Output is correct |
24 |
Correct |
10 ms |
1144 KB |
Output is correct |
25 |
Correct |
32 ms |
1912 KB |
Output is correct |
26 |
Correct |
17 ms |
2056 KB |
Output is correct |
27 |
Correct |
3 ms |
948 KB |
Output is correct |
28 |
Correct |
18 ms |
2044 KB |
Output is correct |
29 |
Correct |
21 ms |
1960 KB |
Output is correct |
30 |
Correct |
19 ms |
2148 KB |
Output is correct |
31 |
Correct |
36 ms |
2040 KB |
Output is correct |
32 |
Correct |
10 ms |
1344 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
19 ms |
2220 KB |
Output is correct |
35 |
Correct |
5 ms |
1016 KB |
Output is correct |
36 |
Correct |
18 ms |
2028 KB |
Output is correct |
37 |
Correct |
8 ms |
1272 KB |
Output is correct |
38 |
Correct |
3 ms |
972 KB |
Output is correct |
39 |
Correct |
19 ms |
2100 KB |
Output is correct |
40 |
Correct |
53 ms |
1960 KB |
Output is correct |
41 |
Correct |
36 ms |
2040 KB |
Output is correct |
42 |
Correct |
33 ms |
1996 KB |
Output is correct |
43 |
Correct |
19 ms |
2124 KB |
Output is correct |
44 |
Correct |
19 ms |
2096 KB |
Output is correct |
45 |
Correct |
30 ms |
2040 KB |
Output is correct |
46 |
Correct |
54 ms |
1964 KB |
Output is correct |
47 |
Correct |
24 ms |
2092 KB |
Output is correct |
48 |
Correct |
51 ms |
2000 KB |
Output is correct |
49 |
Correct |
44 ms |
2044 KB |
Output is correct |
50 |
Correct |
19 ms |
2140 KB |
Output is correct |
51 |
Correct |
19 ms |
2092 KB |
Output is correct |
52 |
Correct |
48 ms |
2040 KB |
Output is correct |
53 |
Correct |
4 ms |
888 KB |
Output is correct |
54 |
Correct |
32 ms |
1960 KB |
Output is correct |
55 |
Correct |
18 ms |
2120 KB |
Output is correct |
56 |
Correct |
28 ms |
1960 KB |
Output is correct |
57 |
Correct |
18 ms |
2124 KB |
Output is correct |
58 |
Correct |
34 ms |
2044 KB |
Output is correct |
59 |
Correct |
28 ms |
2156 KB |
Output is correct |
60 |
Correct |
27 ms |
1960 KB |
Output is correct |
61 |
Correct |
3 ms |
1092 KB |
Output is correct |
62 |
Correct |
3 ms |
1032 KB |
Output is correct |
63 |
Correct |
5 ms |
956 KB |
Output is correct |
64 |
Correct |
4 ms |
1016 KB |
Output is correct |
65 |
Correct |
2 ms |
884 KB |
Output is correct |
66 |
Correct |
4 ms |
760 KB |
Output is correct |
67 |
Correct |
8 ms |
760 KB |
Output is correct |
68 |
Correct |
4 ms |
860 KB |
Output is correct |
69 |
Correct |
2 ms |
880 KB |
Output is correct |
70 |
Correct |
5 ms |
764 KB |
Output is correct |
71 |
Correct |
48 ms |
2040 KB |
Output is correct |
72 |
Correct |
6 ms |
1408 KB |
Output is correct |
73 |
Correct |
30 ms |
2064 KB |
Output is correct |
74 |
Correct |
32 ms |
2040 KB |
Output is correct |
75 |
Correct |
5 ms |
896 KB |
Output is correct |
76 |
Correct |
18 ms |
2132 KB |
Output is correct |
77 |
Correct |
58 ms |
1960 KB |
Output is correct |
78 |
Correct |
5 ms |
1420 KB |
Output is correct |
79 |
Correct |
12 ms |
2052 KB |
Output is correct |
80 |
Correct |
21 ms |
2052 KB |
Output is correct |
81 |
Correct |
50 ms |
2040 KB |
Output is correct |
82 |
Correct |
43 ms |
2052 KB |
Output is correct |
83 |
Correct |
5 ms |
1024 KB |
Output is correct |
84 |
Correct |
24 ms |
2040 KB |
Output is correct |
85 |
Correct |
45 ms |
2096 KB |
Output is correct |
86 |
Correct |
28 ms |
1744 KB |
Output is correct |
87 |
Correct |
8 ms |
1144 KB |
Output is correct |
88 |
Incorrect |
34 ms |
1028 KB |
Incorrect |
89 |
Halted |
0 ms |
0 KB |
- |