#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> mem[200000];
vector<int> Ask(int i){
if (mem[i].size()) return mem[i];
return mem[i]=ask(i);
}
int find_best(int n) {
for (int i=0; i<n; ++i) mem[i].clear();
// if (n<=5000){
// for (int i=0; i<n; ++i){
// auto tmp=Ask(i);
// if (tmp[0]+tmp[1]==0) return i;
// }
// return -1;
// }
int m=n;
int mx=0;
while (m>1){
m=(int)sqrt(m);
mx+=m;
}
vector<pair<int, int>> v(mx);
for (int i=0; i<mx; ++i){
auto tmp=Ask(i);
v[i]={tmp[0], tmp[1]};
if (tmp[0]+tmp[1]==0) return i;
}
int cnt=0;
for (auto &i:v) cnt=max(cnt, i.first+i.second);
ordered_set<int> id;
vector<int> st;
for (int i=0; i<mx; ++i) if (v[i].first+v[i].second!=cnt) id.insert(i);
for (int i=mx; i<n; ++i) st.push_back(i);
auto solve=[&](auto &&self, vector<int> pos, int cc){
if (!cc || pos.empty()) return;
int mid=((int)pos.size()-1)/2;
vector<int> posl, posr;
for (int j:pos){
if (j<pos[mid]) posl.push_back(j);
if (j>pos[mid]) posr.push_back(j);
}
auto tmp=Ask(pos[mid]);
if (tmp[0]+tmp[1]!=cnt){
id.insert(pos[mid]);
pos.erase(pos.begin()+mid);
self(self, pos, cc-1);
// int l=mid, r=mid;
// while (l){
// --l;
// auto tmp2=Ask(pos[l]);
// if (tmp2[0]+tmp2[1]!=cnt) id.insert(pos[l]), posl.pop_back();
// else{
// int cl=tmp2[0]-id.order_of_key(pos[l]);
// int cr=tmp2[1]-((int)id.size()-id.order_of_key(pos[l]));
// self(self, posl, cl);
// self(self, posr, cr);
// return;
// }
// }
// reverse(posr.begin(), posr.end());
// while (r+1<(int)pos.size()){
// ++r;
// auto tmp2=Ask(pos[r]);
// if (tmp2[0]+tmp2[1]!=cnt) id.insert(pos[r]), posr.pop_back();
// else{
// reverse(posr.begin(), posr.end());
// int cl=tmp2[0]-id.order_of_key(pos[r]);
// int cr=tmp2[1]-((int)id.size()-id.order_of_key(pos[r]));
// self(self, posl, cl);
// self(self, posr, cr);
// return;
// }
// }
}else{
int cl=tmp[0]-id.order_of_key(pos[mid]);
int cr=cc-cl;
self(self, posl, cl);
self(self, posr, cr);
}
};
solve(solve, st, cnt-(int)id.size());
for (int i:id){
auto tmp=Ask(i);
if (tmp[0]+tmp[1]==0) return i;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9356 KB |
Output is correct |
2 |
Correct |
7 ms |
9164 KB |
Output is correct |
3 |
Correct |
8 ms |
9164 KB |
Output is correct |
4 |
Correct |
8 ms |
9104 KB |
Output is correct |
5 |
Correct |
9 ms |
9096 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
10 ms |
9164 KB |
Output is correct |
8 |
Correct |
8 ms |
9084 KB |
Output is correct |
9 |
Correct |
8 ms |
9060 KB |
Output is correct |
10 |
Correct |
7 ms |
9164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9164 KB |
Output is correct |
2 |
Correct |
7 ms |
9164 KB |
Output is correct |
3 |
Correct |
9 ms |
8980 KB |
Output is correct |
4 |
Correct |
8 ms |
9164 KB |
Output is correct |
5 |
Correct |
7 ms |
9164 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
10 ms |
8956 KB |
Output is correct |
8 |
Correct |
11 ms |
9164 KB |
Output is correct |
9 |
Correct |
7 ms |
9164 KB |
Output is correct |
10 |
Correct |
7 ms |
9096 KB |
Output is correct |
11 |
Correct |
13 ms |
9164 KB |
Output is correct |
12 |
Correct |
11 ms |
9096 KB |
Output is correct |
13 |
Correct |
10 ms |
9156 KB |
Output is correct |
14 |
Correct |
10 ms |
5468 KB |
Output is correct |
15 |
Correct |
29 ms |
9484 KB |
Output is correct |
16 |
Correct |
44 ms |
9104 KB |
Output is correct |
17 |
Correct |
3 ms |
4952 KB |
Output is correct |
18 |
Correct |
31 ms |
9308 KB |
Output is correct |
19 |
Correct |
4 ms |
4952 KB |
Output is correct |
20 |
Correct |
16 ms |
7372 KB |
Output is correct |
21 |
Correct |
32 ms |
9164 KB |
Output is correct |
22 |
Correct |
34 ms |
9156 KB |
Output is correct |
23 |
Correct |
12 ms |
9088 KB |
Output is correct |
24 |
Correct |
13 ms |
9100 KB |
Output is correct |
25 |
Correct |
40 ms |
9244 KB |
Output is correct |
26 |
Correct |
34 ms |
9500 KB |
Output is correct |
27 |
Correct |
11 ms |
9128 KB |
Output is correct |
28 |
Correct |
32 ms |
9664 KB |
Output is correct |
29 |
Correct |
32 ms |
9472 KB |
Output is correct |
30 |
Correct |
35 ms |
9292 KB |
Output is correct |
31 |
Correct |
4 ms |
4952 KB |
Output is correct |
32 |
Correct |
12 ms |
9076 KB |
Output is correct |
33 |
Correct |
1 ms |
4952 KB |
Output is correct |
34 |
Correct |
41 ms |
9516 KB |
Output is correct |
35 |
Correct |
10 ms |
9080 KB |
Output is correct |
36 |
Correct |
37 ms |
9108 KB |
Output is correct |
37 |
Correct |
15 ms |
9084 KB |
Output is correct |
38 |
Correct |
10 ms |
9164 KB |
Output is correct |
39 |
Correct |
38 ms |
9524 KB |
Output is correct |
40 |
Correct |
43 ms |
9692 KB |
Output is correct |
41 |
Correct |
35 ms |
9220 KB |
Output is correct |
42 |
Correct |
30 ms |
9420 KB |
Output is correct |
43 |
Correct |
48 ms |
9280 KB |
Output is correct |
44 |
Correct |
42 ms |
9412 KB |
Output is correct |
45 |
Correct |
29 ms |
9164 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
41 ms |
9456 KB |
Output is correct |
48 |
Correct |
31 ms |
9320 KB |
Output is correct |
49 |
Correct |
43 ms |
9920 KB |
Output is correct |
50 |
Correct |
33 ms |
9160 KB |
Output is correct |
51 |
Correct |
39 ms |
9324 KB |
Output is correct |
52 |
Correct |
35 ms |
9420 KB |
Output is correct |
53 |
Correct |
9 ms |
9164 KB |
Output is correct |
54 |
Correct |
38 ms |
9428 KB |
Output is correct |
55 |
Correct |
4 ms |
4952 KB |
Output is correct |
56 |
Correct |
30 ms |
9304 KB |
Output is correct |
57 |
Correct |
37 ms |
9272 KB |
Output is correct |
58 |
Correct |
34 ms |
9344 KB |
Output is correct |
59 |
Correct |
44 ms |
9200 KB |
Output is correct |
60 |
Correct |
30 ms |
9164 KB |
Output is correct |
61 |
Correct |
8 ms |
9164 KB |
Output is correct |
62 |
Correct |
14 ms |
9164 KB |
Output is correct |
63 |
Correct |
9 ms |
9164 KB |
Output is correct |
64 |
Correct |
13 ms |
8908 KB |
Output is correct |
65 |
Correct |
7 ms |
8908 KB |
Output is correct |
66 |
Correct |
11 ms |
10700 KB |
Output is correct |
67 |
Correct |
16 ms |
10688 KB |
Output is correct |
68 |
Correct |
3 ms |
4952 KB |
Output is correct |
69 |
Correct |
14 ms |
10824 KB |
Output is correct |
70 |
Correct |
10 ms |
9676 KB |
Output is correct |
71 |
Partially correct |
33 ms |
9212 KB |
Partially correct - number of queries: 5234 |
72 |
Correct |
14 ms |
9152 KB |
Output is correct |
73 |
Partially correct |
34 ms |
9472 KB |
Partially correct - number of queries: 5171 |
74 |
Partially correct |
35 ms |
9240 KB |
Partially correct - number of queries: 5198 |
75 |
Correct |
9 ms |
9164 KB |
Output is correct |
76 |
Correct |
28 ms |
9408 KB |
Output is correct |
77 |
Correct |
41 ms |
9448 KB |
Output is correct |
78 |
Correct |
13 ms |
9420 KB |
Output is correct |
79 |
Correct |
33 ms |
9164 KB |
Output is correct |
80 |
Correct |
46 ms |
9684 KB |
Output is correct |
81 |
Correct |
26 ms |
9164 KB |
Output is correct |
82 |
Correct |
43 ms |
9420 KB |
Output is correct |
83 |
Correct |
9 ms |
9092 KB |
Output is correct |
84 |
Correct |
36 ms |
9460 KB |
Output is correct |
85 |
Correct |
47 ms |
9696 KB |
Output is correct |
86 |
Correct |
7 ms |
9164 KB |
Output is correct |
87 |
Correct |
7 ms |
8908 KB |
Output is correct |
88 |
Correct |
7 ms |
9104 KB |
Output is correct |
89 |
Correct |
8 ms |
9164 KB |
Output is correct |
90 |
Correct |
10 ms |
8932 KB |
Output is correct |
91 |
Correct |
7 ms |
8908 KB |
Output is correct |
92 |
Correct |
7 ms |
9164 KB |
Output is correct |
93 |
Correct |
13 ms |
9164 KB |
Output is correct |
94 |
Correct |
11 ms |
9164 KB |
Output is correct |
95 |
Correct |
10 ms |
9164 KB |
Output is correct |
96 |
Correct |
11 ms |
9164 KB |
Output is correct |
97 |
Correct |
8 ms |
9164 KB |
Output is correct |