#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
map<int,pair<int,pair<int,int>>> qr;
int cnt = 0;
int cntnonlol;
int n;
pair<int,pair<int,int>> query(int i) {
if(i == n) return mp(cntnonlol,mp(cntnonlol,0));
if(qr.count(i)) return qr[i];
++cnt;
vector<int> perg = ask(i);
return qr[i] = mp(perg[0]+perg[1],mp(perg[0],perg[1]));
}
int find_best(int N) {
n = N;
if(n <= 5000) {
for(int i = 0; i < n; i++) {
if(query(i).fr == 0) return i;
}
}
int S = n/420;
priority_queue<pair<pair<int,int>,pair<int,int>>> q;
for(int i = 0; i*S < n; i++) {
// i*S,(i+1)*S
int l = i*S;
int r = min(n-1,(i+1)*S);
q.push(mp(mp(0,query(r).sc.fr-query(l).sc.fr),mp(l,r)));
}
while(q.size()) {
int l = q.top().sc.fr;
int r = q.top().sc.sc;
q.pop();
if(l > r) continue;
if(query(l).fr == 0) return l;
if(query(r).fr == 0) return r;
if(r-l+1 <= 2) continue;
if(query(l) == query(r)) continue;
int mid = (l+r)/2;
if(l <= mid) q.push(mp(mp(0,query(mid).sc.fr-query(l).sc.fr),mp(l,mid)));
if(mid <= r) q.push(mp(mp(0,query(r).sc.fr-query(mid).sc.fr),mp(mid,r)));
// int ml = (2*l+r)/3;
// int mr = (l+2*r)/3;
// q.push(mp(l,ml));
// q.push(mp(ml,mr));
// q.push(mp(mr,r));
}
assert(false);
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
700 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
708 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
696 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
952 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
2 ms |
960 KB |
Output is correct |
11 |
Correct |
4 ms |
960 KB |
Output is correct |
12 |
Correct |
4 ms |
956 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
6 ms |
944 KB |
Output is correct |
15 |
Correct |
20 ms |
1028 KB |
Output is correct |
16 |
Correct |
7 ms |
1012 KB |
Output is correct |
17 |
Correct |
24 ms |
1372 KB |
Output is correct |
18 |
Correct |
2 ms |
712 KB |
Output is correct |
19 |
Correct |
22 ms |
1688 KB |
Output is correct |
20 |
Correct |
11 ms |
964 KB |
Output is correct |
21 |
Correct |
21 ms |
716 KB |
Output is correct |
22 |
Correct |
17 ms |
1316 KB |
Output is correct |
23 |
Correct |
2 ms |
452 KB |
Output is correct |
24 |
Correct |
3 ms |
480 KB |
Output is correct |
25 |
Correct |
11 ms |
1240 KB |
Output is correct |
26 |
Correct |
13 ms |
1328 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
28 |
Correct |
4 ms |
976 KB |
Output is correct |
29 |
Correct |
5 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
708 KB |
Output is correct |
31 |
Correct |
21 ms |
1024 KB |
Output is correct |
32 |
Correct |
3 ms |
972 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
21 ms |
1268 KB |
Output is correct |
35 |
Correct |
2 ms |
716 KB |
Output is correct |
36 |
Correct |
20 ms |
1632 KB |
Output is correct |
37 |
Correct |
3 ms |
964 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
17 ms |
1096 KB |
Output is correct |
40 |
Correct |
2 ms |
716 KB |
Output is correct |
41 |
Correct |
13 ms |
1540 KB |
Output is correct |
42 |
Correct |
12 ms |
1544 KB |
Output is correct |
43 |
Correct |
11 ms |
1564 KB |
Output is correct |
44 |
Correct |
15 ms |
1048 KB |
Output is correct |
45 |
Correct |
18 ms |
1376 KB |
Output is correct |
46 |
Correct |
24 ms |
1448 KB |
Output is correct |
47 |
Correct |
15 ms |
1260 KB |
Output is correct |
48 |
Correct |
8 ms |
732 KB |
Output is correct |
49 |
Correct |
23 ms |
1380 KB |
Output is correct |
50 |
Correct |
2 ms |
712 KB |
Output is correct |
51 |
Correct |
16 ms |
1104 KB |
Output is correct |
52 |
Correct |
24 ms |
1444 KB |
Output is correct |
53 |
Correct |
2 ms |
464 KB |
Output is correct |
54 |
Correct |
16 ms |
812 KB |
Output is correct |
55 |
Correct |
27 ms |
1728 KB |
Output is correct |
56 |
Correct |
2 ms |
712 KB |
Output is correct |
57 |
Correct |
8 ms |
1220 KB |
Output is correct |
58 |
Correct |
9 ms |
1036 KB |
Output is correct |
59 |
Correct |
11 ms |
1760 KB |
Output is correct |
60 |
Correct |
12 ms |
1028 KB |
Output is correct |
61 |
Correct |
2 ms |
460 KB |
Output is correct |
62 |
Correct |
2 ms |
720 KB |
Output is correct |
63 |
Correct |
2 ms |
712 KB |
Output is correct |
64 |
Correct |
2 ms |
708 KB |
Output is correct |
65 |
Correct |
2 ms |
888 KB |
Output is correct |
66 |
Correct |
2 ms |
716 KB |
Output is correct |
67 |
Correct |
2 ms |
896 KB |
Output is correct |
68 |
Correct |
2 ms |
700 KB |
Output is correct |
69 |
Correct |
2 ms |
956 KB |
Output is correct |
70 |
Correct |
2 ms |
964 KB |
Output is correct |
71 |
Correct |
25 ms |
1356 KB |
Output is correct |
72 |
Correct |
3 ms |
488 KB |
Output is correct |
73 |
Correct |
25 ms |
1004 KB |
Output is correct |
74 |
Correct |
20 ms |
1652 KB |
Output is correct |
75 |
Correct |
2 ms |
724 KB |
Output is correct |
76 |
Correct |
20 ms |
1220 KB |
Output is correct |
77 |
Correct |
27 ms |
1548 KB |
Output is correct |
78 |
Correct |
3 ms |
948 KB |
Output is correct |
79 |
Correct |
13 ms |
1252 KB |
Output is correct |
80 |
Correct |
24 ms |
1752 KB |
Output is correct |
81 |
Correct |
23 ms |
1812 KB |
Output is correct |
82 |
Correct |
24 ms |
1200 KB |
Output is correct |
83 |
Correct |
3 ms |
696 KB |
Output is correct |
84 |
Correct |
17 ms |
2004 KB |
Output is correct |
85 |
Correct |
33 ms |
1212 KB |
Output is correct |
86 |
Correct |
2 ms |
436 KB |
Output is correct |
87 |
Correct |
2 ms |
436 KB |
Output is correct |
88 |
Correct |
2 ms |
436 KB |
Output is correct |
89 |
Correct |
2 ms |
692 KB |
Output is correct |
90 |
Correct |
2 ms |
684 KB |
Output is correct |
91 |
Correct |
2 ms |
708 KB |
Output is correct |
92 |
Correct |
2 ms |
692 KB |
Output is correct |
93 |
Correct |
5 ms |
1240 KB |
Output is correct |
94 |
Correct |
4 ms |
984 KB |
Output is correct |
95 |
Correct |
5 ms |
1484 KB |
Output is correct |
96 |
Correct |
5 ms |
976 KB |
Output is correct |
97 |
Correct |
2 ms |
692 KB |
Output is correct |