#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int L[200000],R[200000],tree[1<<19];
set<int>st;
void update(int x){
x+=1<<18;
while(x){
tree[x]++;
x/=2;
}
}
int calc(int l,int r){
l+=1<<18;
r+=1<<18;
int a=0;
while(l<r){
if(l&1)a+=tree[l];
if(~r&1)a+=tree[r];
l=(l+1)/2;
r=(r-1)/2;
}
if(l==r)a+=tree[l];
return a;
}
int find_best(int n){
for(int i=0;i<n;i++){
L[i]=R[i]=-1;
}
int s=-1;
mt19937 E(869120);
for(int i=0;i<min(600,n);i++){
int t;
do{
t=E()%n;
}while(L[t]!=-1);
vector<int>v=ask(t);
st.insert(t);
L[t]=v[0];
R[t]=v[1];
s=max(s,L[t]+R[t]);
}
int last_val=-1;
for(int i=0;i<s;i++){
int l=last_val;
int r=n-1;
while(l+1!=r){
int m=(l+r)/2;
auto it=st.lower_bound(m);
if(it!=st.end()&&*it<r)m=*it;
else if(it!=st.begin()){
it--;
if(*it>l)m=*it;
}
if(L[m]==-1){
vector<int>v=ask(m);
st.insert(m);
L[m]=v[0];
R[m]=v[1];
}
if(L[m]+R[m]!=s){
r=m;
}
else if(L[m]-calc(0,m)>0){
r=m;
}
else{
l=m;
}
}
if(L[r]==-1){
vector<int>v=ask(r);
st.insert(r);
L[r]=v[0];
R[r]=v[1];
}
update(r);
if(L[r]==0&&R[r]==0){
return r;
}
last_val=r;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1920 KB |
Output is correct |
2 |
Correct |
10 ms |
1952 KB |
Output is correct |
3 |
Correct |
10 ms |
1920 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
9 ms |
1920 KB |
Output is correct |
6 |
Correct |
7 ms |
1920 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
5 ms |
1976 KB |
Output is correct |
9 |
Correct |
7 ms |
1920 KB |
Output is correct |
10 |
Correct |
7 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1952 KB |
Output is correct |
2 |
Correct |
10 ms |
1920 KB |
Output is correct |
3 |
Correct |
10 ms |
1920 KB |
Output is correct |
4 |
Correct |
10 ms |
1968 KB |
Output is correct |
5 |
Correct |
9 ms |
1920 KB |
Output is correct |
6 |
Correct |
11 ms |
1920 KB |
Output is correct |
7 |
Correct |
7 ms |
1920 KB |
Output is correct |
8 |
Correct |
10 ms |
1920 KB |
Output is correct |
9 |
Correct |
8 ms |
1920 KB |
Output is correct |
10 |
Correct |
7 ms |
2052 KB |
Output is correct |
11 |
Correct |
6 ms |
2228 KB |
Output is correct |
12 |
Correct |
10 ms |
1920 KB |
Output is correct |
13 |
Correct |
14 ms |
2548 KB |
Output is correct |
14 |
Correct |
8 ms |
640 KB |
Output is correct |
15 |
Correct |
17 ms |
2196 KB |
Output is correct |
16 |
Correct |
53 ms |
3448 KB |
Output is correct |
17 |
Correct |
9 ms |
1920 KB |
Output is correct |
18 |
Correct |
54 ms |
3704 KB |
Output is correct |
19 |
Correct |
10 ms |
2176 KB |
Output is correct |
20 |
Correct |
13 ms |
1528 KB |
Output is correct |
21 |
Correct |
23 ms |
2600 KB |
Output is correct |
22 |
Correct |
11 ms |
2084 KB |
Output is correct |
23 |
Correct |
10 ms |
1952 KB |
Output is correct |
24 |
Correct |
7 ms |
1920 KB |
Output is correct |
25 |
Correct |
39 ms |
2936 KB |
Output is correct |
26 |
Correct |
31 ms |
2808 KB |
Output is correct |
27 |
Correct |
9 ms |
2048 KB |
Output is correct |
28 |
Correct |
42 ms |
3576 KB |
Output is correct |
29 |
Correct |
51 ms |
3288 KB |
Output is correct |
30 |
Correct |
66 ms |
3648 KB |
Output is correct |
31 |
Correct |
9 ms |
1920 KB |
Output is correct |
32 |
Correct |
11 ms |
2296 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
29 ms |
2520 KB |
Output is correct |
35 |
Correct |
6 ms |
2096 KB |
Output is correct |
36 |
Correct |
14 ms |
2308 KB |
Output is correct |
37 |
Correct |
9 ms |
2048 KB |
Output is correct |
38 |
Correct |
8 ms |
1920 KB |
Output is correct |
39 |
Correct |
16 ms |
2664 KB |
Output is correct |
40 |
Correct |
57 ms |
3704 KB |
Output is correct |
41 |
Correct |
38 ms |
2936 KB |
Output is correct |
42 |
Correct |
37 ms |
2936 KB |
Output is correct |
43 |
Correct |
47 ms |
2936 KB |
Output is correct |
44 |
Correct |
30 ms |
2680 KB |
Output is correct |
45 |
Correct |
22 ms |
2580 KB |
Output is correct |
46 |
Correct |
7 ms |
1920 KB |
Output is correct |
47 |
Correct |
25 ms |
2664 KB |
Output is correct |
48 |
Correct |
23 ms |
3232 KB |
Output is correct |
49 |
Correct |
12 ms |
2048 KB |
Output is correct |
50 |
Correct |
47 ms |
3696 KB |
Output is correct |
51 |
Correct |
34 ms |
2680 KB |
Output is correct |
52 |
Correct |
8 ms |
1956 KB |
Output is correct |
53 |
Correct |
11 ms |
2176 KB |
Output is correct |
54 |
Correct |
20 ms |
2712 KB |
Output is correct |
55 |
Correct |
10 ms |
1920 KB |
Output is correct |
56 |
Correct |
54 ms |
3704 KB |
Output is correct |
57 |
Correct |
37 ms |
3192 KB |
Output is correct |
58 |
Correct |
46 ms |
3212 KB |
Output is correct |
59 |
Correct |
39 ms |
2936 KB |
Output is correct |
60 |
Correct |
35 ms |
2896 KB |
Output is correct |
61 |
Correct |
10 ms |
2176 KB |
Output is correct |
62 |
Correct |
9 ms |
1912 KB |
Output is correct |
63 |
Correct |
8 ms |
2168 KB |
Output is correct |
64 |
Correct |
6 ms |
2100 KB |
Output is correct |
65 |
Correct |
7 ms |
1920 KB |
Output is correct |
66 |
Correct |
12 ms |
1920 KB |
Output is correct |
67 |
Correct |
7 ms |
1968 KB |
Output is correct |
68 |
Correct |
17 ms |
1920 KB |
Output is correct |
69 |
Correct |
14 ms |
1920 KB |
Output is correct |
70 |
Correct |
8 ms |
1920 KB |
Output is correct |
71 |
Correct |
50 ms |
3704 KB |
Output is correct |
72 |
Correct |
11 ms |
2592 KB |
Output is correct |
73 |
Correct |
41 ms |
3708 KB |
Output is correct |
74 |
Correct |
34 ms |
3784 KB |
Output is correct |
75 |
Correct |
9 ms |
2176 KB |
Output is correct |
76 |
Correct |
45 ms |
3704 KB |
Output is correct |
77 |
Correct |
45 ms |
3704 KB |
Output is correct |
78 |
Correct |
7 ms |
2584 KB |
Output is correct |
79 |
Correct |
28 ms |
3448 KB |
Output is correct |
80 |
Correct |
54 ms |
3704 KB |
Output is correct |
81 |
Correct |
49 ms |
3644 KB |
Output is correct |
82 |
Correct |
54 ms |
3632 KB |
Output is correct |
83 |
Correct |
9 ms |
2048 KB |
Output is correct |
84 |
Correct |
44 ms |
3704 KB |
Output is correct |
85 |
Correct |
43 ms |
3756 KB |
Output is correct |
86 |
Correct |
42 ms |
3576 KB |
Output is correct |
87 |
Correct |
9 ms |
2432 KB |
Output is correct |
88 |
Correct |
47 ms |
3580 KB |
Output is correct |
89 |
Correct |
24 ms |
2680 KB |
Output is correct |
90 |
Correct |
5 ms |
2076 KB |
Output is correct |
91 |
Correct |
26 ms |
3096 KB |
Output is correct |
92 |
Correct |
35 ms |
3064 KB |
Output is correct |
93 |
Correct |
42 ms |
3504 KB |
Output is correct |
94 |
Correct |
53 ms |
3576 KB |
Output is correct |
95 |
Correct |
52 ms |
3704 KB |
Output is correct |
96 |
Correct |
53 ms |
3576 KB |
Output is correct |
97 |
Correct |
57 ms |
3452 KB |
Output is correct |