#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int bit[MAXN];
void add(int pos, int x, int n){ for(;pos<=n;pos+=(pos&-pos)) bit[pos]+=x; }
int get(int pos){
int ret=0;
for(;pos>0;pos-=(pos&-pos)) ret+=bit[pos];
return ret;
}
pii memo[MAXN];
pii query(int x){
if(memo[x].fi!=-1) return memo[x];
vector<int> temp=ask(x);
return memo[x]={temp[0], temp[1]};
}
int mark[MAXN], tot;
int getNext(int l, int r, int comp, int n){
if(r<l) return -1;
int curr=(l+r)>>1;
pii at=query(curr);
if(!mark[curr] && at.fi+at.se<comp){
mark[curr]=1;
add(curr+1, 1, n);
return curr;
}
if(at.fi+at.se==comp){
if(at.se>get(n)-get(curr+1)) return getNext(curr+1, r, comp, n);
return getNext(l, curr-1, comp, n);
}
int temp=getNext(curr+1, r, comp, n);
if(temp!=-1) return temp;
return getNext(l, curr-1, comp, n);
}
int find_best(int n){
for(int i=0;i<n;i++) memo[i]={-1, -1};
int ver=-1, val=-1;
for(int i=0;i<8;i++){
int curr=rng()%n;
pii at=query(curr);
if(at.fi+at.se>val){
val=at.fi+at.se;
ver=curr;
}
}
for(int i=0;i<query(ver).se;i++){
int curr=getNext(ver+1, n-1, val, n);
tot++;
if(curr==-1) break;
pii aux=query(curr);
if(aux.fi+aux.se==0)
return curr;
}
tot=query(ver).se;
for(int i=0;i<query(ver).fi;i++){
int curr=getNext(0, ver-1, val, n);
tot++;
if(curr==-1) break;
pii aux=query(curr);
if(aux.fi+aux.se==0)
return curr;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2620 KB |
Output is correct |
2 |
Correct |
1 ms |
2624 KB |
Output is correct |
3 |
Correct |
1 ms |
2620 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2624 KB |
Output is correct |
6 |
Correct |
1 ms |
2624 KB |
Output is correct |
7 |
Correct |
1 ms |
2624 KB |
Output is correct |
8 |
Correct |
1 ms |
2620 KB |
Output is correct |
9 |
Correct |
1 ms |
2620 KB |
Output is correct |
10 |
Correct |
1 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2624 KB |
Output is correct |
3 |
Correct |
1 ms |
2628 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2624 KB |
Output is correct |
6 |
Correct |
1 ms |
2624 KB |
Output is correct |
7 |
Correct |
1 ms |
2780 KB |
Output is correct |
8 |
Correct |
1 ms |
2620 KB |
Output is correct |
9 |
Correct |
1 ms |
2620 KB |
Output is correct |
10 |
Correct |
1 ms |
2624 KB |
Output is correct |
11 |
Correct |
2 ms |
2884 KB |
Output is correct |
12 |
Correct |
3 ms |
3312 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
4 ms |
3016 KB |
Output is correct |
15 |
Correct |
15 ms |
3452 KB |
Output is correct |
16 |
Correct |
5 ms |
3184 KB |
Output is correct |
17 |
Correct |
26 ms |
4116 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
24 ms |
3744 KB |
Output is correct |
20 |
Correct |
9 ms |
3316 KB |
Output is correct |
21 |
Correct |
16 ms |
3480 KB |
Output is correct |
22 |
Correct |
21 ms |
3396 KB |
Output is correct |
23 |
Correct |
1 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
3180 KB |
Output is correct |
25 |
Correct |
9 ms |
3600 KB |
Output is correct |
26 |
Correct |
11 ms |
3144 KB |
Output is correct |
27 |
Correct |
1 ms |
2640 KB |
Output is correct |
28 |
Correct |
1 ms |
2624 KB |
Output is correct |
29 |
Correct |
2 ms |
2900 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
22 ms |
4188 KB |
Output is correct |
32 |
Correct |
2 ms |
2632 KB |
Output is correct |
33 |
Correct |
1 ms |
2500 KB |
Output is correct |
34 |
Correct |
13 ms |
3744 KB |
Output is correct |
35 |
Correct |
1 ms |
2892 KB |
Output is correct |
36 |
Correct |
15 ms |
3764 KB |
Output is correct |
37 |
Correct |
2 ms |
2904 KB |
Output is correct |
38 |
Correct |
2 ms |
2892 KB |
Output is correct |
39 |
Correct |
11 ms |
3528 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
8 ms |
3600 KB |
Output is correct |
42 |
Correct |
8 ms |
3992 KB |
Output is correct |
43 |
Correct |
8 ms |
3148 KB |
Output is correct |
44 |
Correct |
17 ms |
3536 KB |
Output is correct |
45 |
Correct |
13 ms |
4092 KB |
Output is correct |
46 |
Correct |
23 ms |
4284 KB |
Output is correct |
47 |
Correct |
8 ms |
3356 KB |
Output is correct |
48 |
Correct |
7 ms |
3472 KB |
Output is correct |
49 |
Correct |
15 ms |
4404 KB |
Output is correct |
50 |
Correct |
1 ms |
2648 KB |
Output is correct |
51 |
Correct |
17 ms |
3852 KB |
Output is correct |
52 |
Correct |
18 ms |
4212 KB |
Output is correct |
53 |
Correct |
1 ms |
2624 KB |
Output is correct |
54 |
Correct |
13 ms |
3304 KB |
Output is correct |
55 |
Correct |
24 ms |
3536 KB |
Output is correct |
56 |
Correct |
1 ms |
2392 KB |
Output is correct |
57 |
Correct |
6 ms |
2724 KB |
Output is correct |
58 |
Correct |
5 ms |
3456 KB |
Output is correct |
59 |
Correct |
10 ms |
3692 KB |
Output is correct |
60 |
Correct |
9 ms |
3192 KB |
Output is correct |
61 |
Correct |
1 ms |
2780 KB |
Output is correct |
62 |
Correct |
1 ms |
2892 KB |
Output is correct |
63 |
Correct |
1 ms |
2620 KB |
Output is correct |
64 |
Correct |
1 ms |
2636 KB |
Output is correct |
65 |
Correct |
1 ms |
2388 KB |
Output is correct |
66 |
Correct |
1 ms |
2392 KB |
Output is correct |
67 |
Correct |
3 ms |
2388 KB |
Output is correct |
68 |
Correct |
1 ms |
2624 KB |
Output is correct |
69 |
Correct |
1 ms |
2392 KB |
Output is correct |
70 |
Correct |
2 ms |
2392 KB |
Output is correct |
71 |
Correct |
27 ms |
3444 KB |
Output is correct |
72 |
Correct |
3 ms |
2968 KB |
Output is correct |
73 |
Correct |
22 ms |
3668 KB |
Output is correct |
74 |
Correct |
28 ms |
4208 KB |
Output is correct |
75 |
Correct |
1 ms |
2748 KB |
Output is correct |
76 |
Correct |
22 ms |
4704 KB |
Output is correct |
77 |
Correct |
21 ms |
4300 KB |
Output is correct |
78 |
Correct |
2 ms |
3136 KB |
Output is correct |
79 |
Correct |
9 ms |
4160 KB |
Output is correct |
80 |
Correct |
24 ms |
4156 KB |
Output is correct |
81 |
Correct |
23 ms |
4412 KB |
Output is correct |
82 |
Correct |
26 ms |
3948 KB |
Output is correct |
83 |
Correct |
1 ms |
2620 KB |
Output is correct |
84 |
Correct |
19 ms |
3812 KB |
Output is correct |
85 |
Correct |
25 ms |
4324 KB |
Output is correct |
86 |
Correct |
2 ms |
3072 KB |
Output is correct |
87 |
Correct |
1 ms |
2624 KB |
Output is correct |
88 |
Correct |
1 ms |
3136 KB |
Output is correct |
89 |
Correct |
2 ms |
2880 KB |
Output is correct |
90 |
Correct |
1 ms |
2392 KB |
Output is correct |
91 |
Correct |
1 ms |
2628 KB |
Output is correct |
92 |
Correct |
1 ms |
2392 KB |
Output is correct |
93 |
Correct |
2 ms |
2848 KB |
Output is correct |
94 |
Correct |
2 ms |
2880 KB |
Output is correct |
95 |
Correct |
2 ms |
2912 KB |
Output is correct |
96 |
Correct |
2 ms |
3012 KB |
Output is correct |
97 |
Correct |
1 ms |
2620 KB |
Output is correct |