#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 cnt=0;
{
auto tmp=Ask(0);
cnt=tmp[0]+tmp[1];
}
if (!cnt) return 0;
ordered_set<int> id;
vector<int> st;
for (int i=1; 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){
cnt=tmp[0]+tmp[1];
st.clear();
for (int i=0; i<n; ++i) if (mem[i].size()){
if (mem[i][0]+mem[i][1]<cnt) id.insert(i);
}else st.push_back(i);
self(self, st, cnt-(int)id.size());
}if (tmp[0]+tmp[1]!=cnt){
id.insert(pos[mid]);
pos.erase(pos.begin()+mid);
self(self, pos, cc-1);
}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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
5 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8652 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
5 ms |
8652 KB |
Output is correct |
8 |
Correct |
5 ms |
8652 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
7 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8652 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
5 ms |
8652 KB |
Output is correct |
8 |
Correct |
6 ms |
8652 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8908 KB |
Output is correct |
11 |
Correct |
9 ms |
9164 KB |
Output is correct |
12 |
Correct |
9 ms |
9164 KB |
Output is correct |
13 |
Correct |
11 ms |
9164 KB |
Output is correct |
14 |
Correct |
9 ms |
5720 KB |
Output is correct |
15 |
Correct |
28 ms |
9252 KB |
Output is correct |
16 |
Correct |
28 ms |
9164 KB |
Output is correct |
17 |
Correct |
34 ms |
9464 KB |
Output is correct |
18 |
Correct |
26 ms |
9164 KB |
Output is correct |
19 |
Correct |
29 ms |
9236 KB |
Output is correct |
20 |
Correct |
22 ms |
7368 KB |
Output is correct |
21 |
Correct |
27 ms |
9420 KB |
Output is correct |
22 |
Correct |
25 ms |
9188 KB |
Output is correct |
23 |
Correct |
7 ms |
9164 KB |
Output is correct |
24 |
Correct |
9 ms |
8908 KB |
Output is correct |
25 |
Correct |
30 ms |
9464 KB |
Output is correct |
26 |
Correct |
38 ms |
9708 KB |
Output is correct |
27 |
Correct |
11 ms |
8908 KB |
Output is correct |
28 |
Correct |
26 ms |
9420 KB |
Output is correct |
29 |
Correct |
29 ms |
9236 KB |
Output is correct |
30 |
Correct |
35 ms |
9756 KB |
Output is correct |
31 |
Correct |
32 ms |
9412 KB |
Output is correct |
32 |
Correct |
10 ms |
9160 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
27 ms |
9200 KB |
Output is correct |
35 |
Correct |
7 ms |
9164 KB |
Output is correct |
36 |
Correct |
28 ms |
9224 KB |
Output is correct |
37 |
Correct |
8 ms |
8908 KB |
Output is correct |
38 |
Correct |
10 ms |
9156 KB |
Output is correct |
39 |
Correct |
33 ms |
9420 KB |
Output is correct |
40 |
Correct |
21 ms |
9244 KB |
Output is correct |
41 |
Correct |
34 ms |
9164 KB |
Output is correct |
42 |
Correct |
36 ms |
9412 KB |
Output is correct |
43 |
Correct |
30 ms |
9736 KB |
Output is correct |
44 |
Correct |
29 ms |
9212 KB |
Output is correct |
45 |
Correct |
23 ms |
9268 KB |
Output is correct |
46 |
Correct |
31 ms |
9412 KB |
Output is correct |
47 |
Correct |
26 ms |
9420 KB |
Output is correct |
48 |
Correct |
29 ms |
9420 KB |
Output is correct |
49 |
Correct |
28 ms |
9412 KB |
Output is correct |
50 |
Correct |
38 ms |
9164 KB |
Output is correct |
51 |
Correct |
28 ms |
9164 KB |
Output is correct |
52 |
Correct |
39 ms |
9396 KB |
Output is correct |
53 |
Correct |
7 ms |
8908 KB |
Output is correct |
54 |
Correct |
30 ms |
9452 KB |
Output is correct |
55 |
Correct |
31 ms |
9508 KB |
Output is correct |
56 |
Correct |
31 ms |
9548 KB |
Output is correct |
57 |
Correct |
28 ms |
9408 KB |
Output is correct |
58 |
Correct |
39 ms |
9708 KB |
Output is correct |
59 |
Correct |
26 ms |
9356 KB |
Output is correct |
60 |
Correct |
29 ms |
9164 KB |
Output is correct |
61 |
Correct |
7 ms |
9164 KB |
Output is correct |
62 |
Correct |
8 ms |
9164 KB |
Output is correct |
63 |
Correct |
7 ms |
9164 KB |
Output is correct |
64 |
Correct |
7 ms |
9164 KB |
Output is correct |
65 |
Correct |
8 ms |
10700 KB |
Output is correct |
66 |
Correct |
9 ms |
10952 KB |
Output is correct |
67 |
Correct |
10 ms |
10956 KB |
Output is correct |
68 |
Correct |
11 ms |
12236 KB |
Output is correct |
69 |
Correct |
11 ms |
10700 KB |
Output is correct |
70 |
Correct |
7 ms |
9676 KB |
Output is correct |
71 |
Correct |
34 ms |
9232 KB |
Output is correct |
72 |
Correct |
10 ms |
9168 KB |
Output is correct |
73 |
Correct |
34 ms |
9660 KB |
Output is correct |
74 |
Correct |
43 ms |
9672 KB |
Output is correct |
75 |
Correct |
8 ms |
8908 KB |
Output is correct |
76 |
Correct |
37 ms |
9444 KB |
Output is correct |
77 |
Correct |
30 ms |
9412 KB |
Output is correct |
78 |
Correct |
9 ms |
9164 KB |
Output is correct |
79 |
Correct |
17 ms |
9164 KB |
Output is correct |
80 |
Correct |
40 ms |
9420 KB |
Output is correct |
81 |
Correct |
26 ms |
9188 KB |
Output is correct |
82 |
Correct |
40 ms |
9168 KB |
Output is correct |
83 |
Correct |
7 ms |
8908 KB |
Output is correct |
84 |
Correct |
32 ms |
9484 KB |
Output is correct |
85 |
Correct |
30 ms |
9420 KB |
Output is correct |
86 |
Correct |
18 ms |
13124 KB |
Output is correct |
87 |
Correct |
11 ms |
12508 KB |
Output is correct |
88 |
Correct |
19 ms |
13140 KB |
Output is correct |
89 |
Correct |
18 ms |
13244 KB |
Output is correct |
90 |
Correct |
12 ms |
11968 KB |
Output is correct |
91 |
Correct |
17 ms |
14176 KB |
Output is correct |
92 |
Correct |
178 ms |
187588 KB |
Output is correct |
93 |
Correct |
10 ms |
9164 KB |
Output is correct |
94 |
Correct |
8 ms |
9164 KB |
Output is correct |
95 |
Correct |
9 ms |
9164 KB |
Output is correct |
96 |
Correct |
8 ms |
8908 KB |
Output is correct |
97 |
Correct |
6 ms |
8908 KB |
Output is correct |