#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
const int B = 512;
const int maxn = 2e5+5;
vector<int> res[maxn];
vector<int> get(int x){
if(!res[x].empty()) return res[x];
res[x]=ask(x);res[x][1]+=res[x][0];
return res[x];
}
int N,bit[maxn],Max;
void update(int x){
for(int i=x+1;i<=N;i+=(i&(-i))) bit[i]++;
}
int query(int x){
int ans=0;
for(int i=x+1;i>=1;i-=(i&(-i))) ans+=bit[i];
return ans;
}
int find_best(int n){
N=n;
for(int i=0;i<474;i++){
vector<int> cc=get(i);
if(cc[1]==0) return i;
Max=max(Max,cc[1]);
}
for(int i=0;i<n;i+=B){
vector<int> p;
for(int j=i;j<min(i+B,n);j++) p.push_back(j);
while(true){
int l=0,r=(int)p.size()-1;
bool check=false;
while(l<=r){
int mid=(l+r)>>1;
vector<int> cc=get(p[mid]);
if(cc[1]==0) return p[mid];
if(cc[1]<Max){
update(p[mid]);
p.erase(p.begin()+mid);
check=true;
break;
}
if(cc[0]-query(p[mid])) r=mid-1;
else l=mid+1;
}
if(!check) break;
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5720 KB |
Output is correct |
2 |
Correct |
14 ms |
6008 KB |
Output is correct |
3 |
Correct |
12 ms |
5720 KB |
Output is correct |
4 |
Correct |
22 ms |
5976 KB |
Output is correct |
5 |
Correct |
17 ms |
5788 KB |
Output is correct |
6 |
Correct |
1 ms |
5720 KB |
Output is correct |
7 |
Correct |
12 ms |
5720 KB |
Output is correct |
8 |
Correct |
8 ms |
5720 KB |
Output is correct |
9 |
Correct |
9 ms |
5720 KB |
Output is correct |
10 |
Correct |
18 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5720 KB |
Output is correct |
2 |
Correct |
15 ms |
5720 KB |
Output is correct |
3 |
Correct |
9 ms |
5720 KB |
Output is correct |
4 |
Correct |
26 ms |
6540 KB |
Output is correct |
5 |
Correct |
12 ms |
5776 KB |
Output is correct |
6 |
Correct |
1 ms |
5720 KB |
Output is correct |
7 |
Correct |
12 ms |
5720 KB |
Output is correct |
8 |
Correct |
12 ms |
5720 KB |
Output is correct |
9 |
Correct |
11 ms |
5976 KB |
Output is correct |
10 |
Correct |
29 ms |
5996 KB |
Output is correct |
11 |
Correct |
13 ms |
5968 KB |
Output is correct |
12 |
Correct |
3 ms |
5720 KB |
Output is correct |
13 |
Correct |
20 ms |
5728 KB |
Output is correct |
14 |
Correct |
4 ms |
5720 KB |
Output is correct |
15 |
Correct |
8 ms |
5720 KB |
Output is correct |
16 |
Partially correct |
47 ms |
6784 KB |
Partially correct - number of queries: 6145 |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Partially correct |
37 ms |
6284 KB |
Partially correct - number of queries: 7388 |
19 |
Correct |
3 ms |
5976 KB |
Output is correct |
20 |
Correct |
8 ms |
5720 KB |
Output is correct |
21 |
Correct |
16 ms |
5964 KB |
Output is correct |
22 |
Correct |
8 ms |
5720 KB |
Output is correct |
23 |
Correct |
7 ms |
5720 KB |
Output is correct |
24 |
Correct |
4 ms |
5720 KB |
Output is correct |
25 |
Correct |
20 ms |
5976 KB |
Output is correct |
26 |
Correct |
22 ms |
6232 KB |
Output is correct |
27 |
Correct |
10 ms |
6268 KB |
Output is correct |
28 |
Partially correct |
31 ms |
5976 KB |
Partially correct - number of queries: 7007 |
29 |
Partially correct |
27 ms |
6032 KB |
Partially correct - number of queries: 5887 |
30 |
Partially correct |
44 ms |
6292 KB |
Partially correct - number of queries: 7174 |
31 |
Correct |
4 ms |
5720 KB |
Output is correct |
32 |
Correct |
16 ms |
5720 KB |
Output is correct |
33 |
Correct |
1 ms |
5720 KB |
Output is correct |
34 |
Correct |
13 ms |
5920 KB |
Output is correct |
35 |
Correct |
15 ms |
5792 KB |
Output is correct |
36 |
Correct |
11 ms |
5976 KB |
Output is correct |
37 |
Correct |
8 ms |
5976 KB |
Output is correct |
38 |
Correct |
6 ms |
5996 KB |
Output is correct |
39 |
Correct |
17 ms |
5976 KB |
Output is correct |
40 |
Partially correct |
42 ms |
6356 KB |
Partially correct - number of queries: 6718 |
41 |
Correct |
25 ms |
6244 KB |
Output is correct |
42 |
Correct |
23 ms |
6260 KB |
Output is correct |
43 |
Correct |
19 ms |
6232 KB |
Output is correct |
44 |
Correct |
15 ms |
5976 KB |
Output is correct |
45 |
Correct |
13 ms |
6092 KB |
Output is correct |
46 |
Correct |
3 ms |
5716 KB |
Output is correct |
47 |
Correct |
23 ms |
5884 KB |
Output is correct |
48 |
Partially correct |
33 ms |
6048 KB |
Partially correct - number of queries: 5343 |
49 |
Correct |
8 ms |
5716 KB |
Output is correct |
50 |
Partially correct |
34 ms |
6224 KB |
Partially correct - number of queries: 7321 |
51 |
Correct |
15 ms |
5828 KB |
Output is correct |
52 |
Correct |
4 ms |
5976 KB |
Output is correct |
53 |
Correct |
21 ms |
5976 KB |
Output is correct |
54 |
Correct |
12 ms |
5976 KB |
Output is correct |
55 |
Correct |
3 ms |
5720 KB |
Output is correct |
56 |
Partially correct |
36 ms |
6052 KB |
Partially correct - number of queries: 7300 |
57 |
Partially correct |
18 ms |
5976 KB |
Partially correct - number of queries: 5306 |
58 |
Partially correct |
27 ms |
6060 KB |
Partially correct - number of queries: 5422 |
59 |
Correct |
22 ms |
6144 KB |
Output is correct |
60 |
Correct |
13 ms |
5976 KB |
Output is correct |
61 |
Correct |
17 ms |
5720 KB |
Output is correct |
62 |
Correct |
3 ms |
5720 KB |
Output is correct |
63 |
Correct |
13 ms |
6068 KB |
Output is correct |
64 |
Correct |
19 ms |
5976 KB |
Output is correct |
65 |
Correct |
16 ms |
5980 KB |
Output is correct |
66 |
Correct |
21 ms |
5792 KB |
Output is correct |
67 |
Correct |
28 ms |
6080 KB |
Output is correct |
68 |
Correct |
4 ms |
5720 KB |
Output is correct |
69 |
Correct |
20 ms |
5720 KB |
Output is correct |
70 |
Correct |
16 ms |
5720 KB |
Output is correct |
71 |
Partially correct |
32 ms |
6224 KB |
Partially correct - number of queries: 8069 |
72 |
Correct |
32 ms |
5968 KB |
Output is correct |
73 |
Partially correct |
43 ms |
6228 KB |
Partially correct - number of queries: 8020 |
74 |
Partially correct |
52 ms |
6312 KB |
Partially correct - number of queries: 8041 |
75 |
Correct |
15 ms |
5720 KB |
Output is correct |
76 |
Partially correct |
48 ms |
6116 KB |
Partially correct - number of queries: 7564 |
77 |
Partially correct |
47 ms |
6224 KB |
Partially correct - number of queries: 7584 |
78 |
Correct |
29 ms |
6256 KB |
Output is correct |
79 |
Partially correct |
28 ms |
5980 KB |
Partially correct - number of queries: 5833 |
80 |
Partially correct |
27 ms |
6260 KB |
Partially correct - number of queries: 7565 |
81 |
Partially correct |
42 ms |
5976 KB |
Partially correct - number of queries: 7610 |
82 |
Partially correct |
43 ms |
6628 KB |
Partially correct - number of queries: 7577 |
83 |
Correct |
17 ms |
5784 KB |
Output is correct |
84 |
Partially correct |
41 ms |
6088 KB |
Partially correct - number of queries: 6997 |
85 |
Partially correct |
32 ms |
6588 KB |
Partially correct - number of queries: 7568 |
86 |
Correct |
16 ms |
6008 KB |
Output is correct |
87 |
Correct |
27 ms |
6060 KB |
Output is correct |
88 |
Correct |
16 ms |
5720 KB |
Output is correct |
89 |
Correct |
13 ms |
5804 KB |
Output is correct |
90 |
Correct |
14 ms |
5720 KB |
Output is correct |
91 |
Correct |
16 ms |
5720 KB |
Output is correct |
92 |
Correct |
19 ms |
6120 KB |
Output is correct |
93 |
Correct |
26 ms |
5720 KB |
Output is correct |
94 |
Correct |
21 ms |
5976 KB |
Output is correct |
95 |
Correct |
22 ms |
5720 KB |
Output is correct |
96 |
Correct |
30 ms |
5992 KB |
Output is correct |
97 |
Correct |
21 ms |
6000 KB |
Output is correct |