#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define sz(s) (int)s.size()
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int MAX=2e5+10;
bool use[MAX];
pii res[MAX];
int cq;
pii cnt(int pos){
if(use[pos])return res[pos];
use[pos]=1;
cq++;
vector<int> v=ask(pos);
return res[pos]={v[0],v[1]};
}
int sum(int pos){
pii c=cnt(pos);
return c.F+c.S;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){
return rng()%(r-l+1)+l;
}
int cntMx;
int find_best(int n){
cntMx=0;
int L=500;
int r=0;
for(int j=0;j<min(n,L);j++){
cntMx=max(cntMx,sum(j));
r++;
if(sum(j)==0)return j;
if(cntMx>n/2)break;
}
int pref=0;
for(int j=0;j<r;j++){
if(sum(j)!=cntMx)pref++;
}
queue<pair<pii,pii>> q;
q.push({{r,n-1},{cntMx,pref}});
while(!q.empty()){
int l=q.front().F.F,r=q.front().F.S,c=q.front().S.F,pl=q.front().S.S;
q.pop();
if(c==0)continue;
if(c==r-l+1){
for(int i=l;i<=r;i++){
if(sum(i)==0){
return i;
}
}
continue;
}
int tl=(l+r)/2,tr=(l+r)/2;
while(tl>=l&&sum(tl)!=cntMx){
if(sum(tl)==0){
return tl;
}
tl--;
}
while(tr<=r&&sum(tr)!=cntMx){
if(sum(tr)==0){
return tr;
}
tr++;
}
if(tl>=0){
int L=cnt(tl).F-pl;
if(l<=tl-1)q.push({{l,tl-1},{L,pl}});
}
if(tr<n){
int R=c-cnt(tr).F+pl;
if(tr+1<=r){
q.push({{tr+1,r},{R,cnt(tr).F}});
}
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
3 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
988 KB |
Output is correct |
12 |
Correct |
6 ms |
1112 KB |
Output is correct |
13 |
Correct |
4 ms |
1112 KB |
Output is correct |
14 |
Correct |
8 ms |
600 KB |
Output is correct |
15 |
Correct |
17 ms |
2244 KB |
Output is correct |
16 |
Partially correct |
25 ms |
2036 KB |
Partially correct - number of queries: 5117 |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Partially correct |
28 ms |
2432 KB |
Partially correct - number of queries: 5097 |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
1112 KB |
Output is correct |
21 |
Correct |
12 ms |
2392 KB |
Output is correct |
22 |
Correct |
20 ms |
2136 KB |
Output is correct |
23 |
Correct |
2 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
856 KB |
Output is correct |
25 |
Correct |
14 ms |
2380 KB |
Output is correct |
26 |
Correct |
13 ms |
2136 KB |
Output is correct |
27 |
Correct |
3 ms |
600 KB |
Output is correct |
28 |
Correct |
18 ms |
1992 KB |
Output is correct |
29 |
Correct |
19 ms |
1880 KB |
Output is correct |
30 |
Partially correct |
25 ms |
2136 KB |
Partially correct - number of queries: 5059 |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
1112 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
18 ms |
1992 KB |
Output is correct |
35 |
Correct |
3 ms |
600 KB |
Output is correct |
36 |
Correct |
21 ms |
2136 KB |
Output is correct |
37 |
Correct |
4 ms |
956 KB |
Output is correct |
38 |
Correct |
4 ms |
856 KB |
Output is correct |
39 |
Correct |
16 ms |
2136 KB |
Output is correct |
40 |
Correct |
22 ms |
2136 KB |
Output is correct |
41 |
Partially correct |
22 ms |
2136 KB |
Partially correct - number of queries: 5068 |
42 |
Partially correct |
14 ms |
2136 KB |
Partially correct - number of queries: 5068 |
43 |
Correct |
23 ms |
1996 KB |
Output is correct |
44 |
Correct |
24 ms |
2136 KB |
Output is correct |
45 |
Correct |
18 ms |
1992 KB |
Output is correct |
46 |
Correct |
2 ms |
344 KB |
Output is correct |
47 |
Correct |
14 ms |
1880 KB |
Output is correct |
48 |
Partially correct |
21 ms |
2392 KB |
Partially correct - number of queries: 5058 |
49 |
Correct |
26 ms |
2136 KB |
Output is correct |
50 |
Correct |
15 ms |
2136 KB |
Output is correct |
51 |
Correct |
17 ms |
2396 KB |
Output is correct |
52 |
Correct |
19 ms |
2136 KB |
Output is correct |
53 |
Correct |
3 ms |
600 KB |
Output is correct |
54 |
Correct |
16 ms |
2136 KB |
Output is correct |
55 |
Correct |
2 ms |
344 KB |
Output is correct |
56 |
Correct |
21 ms |
1976 KB |
Output is correct |
57 |
Correct |
15 ms |
2136 KB |
Output is correct |
58 |
Correct |
18 ms |
2136 KB |
Output is correct |
59 |
Partially correct |
31 ms |
2136 KB |
Partially correct - number of queries: 5074 |
60 |
Correct |
22 ms |
2136 KB |
Output is correct |
61 |
Correct |
2 ms |
600 KB |
Output is correct |
62 |
Correct |
2 ms |
696 KB |
Output is correct |
63 |
Correct |
2 ms |
596 KB |
Output is correct |
64 |
Correct |
3 ms |
596 KB |
Output is correct |
65 |
Correct |
3 ms |
344 KB |
Output is correct |
66 |
Correct |
3 ms |
344 KB |
Output is correct |
67 |
Correct |
2 ms |
344 KB |
Output is correct |
68 |
Correct |
2 ms |
344 KB |
Output is correct |
69 |
Correct |
4 ms |
344 KB |
Output is correct |
70 |
Correct |
3 ms |
344 KB |
Output is correct |
71 |
Partially correct |
19 ms |
2284 KB |
Partially correct - number of queries: 5259 |
72 |
Correct |
6 ms |
1368 KB |
Output is correct |
73 |
Partially correct |
21 ms |
2136 KB |
Partially correct - number of queries: 5196 |
74 |
Partially correct |
24 ms |
2136 KB |
Partially correct - number of queries: 5223 |
75 |
Correct |
4 ms |
600 KB |
Output is correct |
76 |
Correct |
12 ms |
2392 KB |
Output is correct |
77 |
Partially correct |
28 ms |
2124 KB |
Partially correct - number of queries: 5209 |
78 |
Correct |
5 ms |
1112 KB |
Output is correct |
79 |
Correct |
11 ms |
1880 KB |
Output is correct |
80 |
Partially correct |
26 ms |
2136 KB |
Partially correct - number of queries: 5153 |
81 |
Partially correct |
14 ms |
2136 KB |
Partially correct - number of queries: 5194 |
82 |
Partially correct |
19 ms |
2136 KB |
Partially correct - number of queries: 5047 |
83 |
Correct |
2 ms |
600 KB |
Output is correct |
84 |
Correct |
20 ms |
2136 KB |
Output is correct |
85 |
Partially correct |
18 ms |
2136 KB |
Partially correct - number of queries: 5123 |
86 |
Correct |
2 ms |
344 KB |
Output is correct |
87 |
Correct |
3 ms |
344 KB |
Output is correct |
88 |
Correct |
2 ms |
344 KB |
Output is correct |
89 |
Correct |
2 ms |
456 KB |
Output is correct |
90 |
Correct |
3 ms |
600 KB |
Output is correct |
91 |
Correct |
2 ms |
344 KB |
Output is correct |
92 |
Correct |
3 ms |
344 KB |
Output is correct |
93 |
Correct |
2 ms |
856 KB |
Output is correct |
94 |
Correct |
4 ms |
856 KB |
Output is correct |
95 |
Correct |
3 ms |
856 KB |
Output is correct |
96 |
Correct |
5 ms |
856 KB |
Output is correct |
97 |
Correct |
3 ms |
444 KB |
Output is correct |