#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define sz(v) ((int)v.size())
#define pb push_back
#ifdef ONPC
vector<int> p;
vector<int> ask(int x);
#else
#include "prize.h"
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int lv[1000];
int al[200005], ar[200005], a[200005];
void g(int x) {
if (a[x]) return;
a[x] = 1;
auto u = ask(x);
al[x] = u[0];
ar[x] = u[1];
lv[al[x]] = min(lv[al[x]], x);
}
int find_best(int n) {
for (int i = 0; i < 1000; ++i)
lv[i] = n+2;
vector<int> rs(n);
iota(rs.begin(), rs.end(), 0);
shuffle(rs.begin(), rs.end(), rng);
int cn = 0;
for (int i = 0; i < min(n,450); ++i) {
g(rs[i]);
cn = max(cn, al[rs[i]] + ar[rs[i]]);
}
vector<int> sp;
for (int i = 1; i <= cn; ++i) {
int l = (i > 1) ? sp.back()+1 : 0;
int r = n;
for (int j = i; j <= cn; ++j)
r = min(r, lv[j]);
while (l < r) {
int m = (l+r)/2;
g(m);
if (al[m] + ar[m] < cn || al[m] >= i)
r = m;
else
l = m+1;
}
sp.pb(l);
}
assert(sz(sp) == cn);
for (auto x : sp) {
g(x); if (al[x] == 0 && ar[x] == 0) return x;
}
return -1;
}
#ifdef ONPC
vector<int> ask(int x) {
vector<int> r(2,0);
for (int i = 0; i < x; ++i) if (p[i] < p[x]) ++r[0];
for (int i = x+1; i < sz(p); ++i) if (p[i] < p[x]) ++r[1];
return r;
}
int main() {
int n;
cin >>n; p.resize(n);
for (int i = 0; i < n; ++i)
cin >> p[i];
cout << find_best(n) << endl;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3144 KB |
Output is correct |
2 |
Correct |
7 ms |
3188 KB |
Output is correct |
3 |
Correct |
7 ms |
3200 KB |
Output is correct |
4 |
Correct |
9 ms |
3116 KB |
Output is correct |
5 |
Correct |
7 ms |
3116 KB |
Output is correct |
6 |
Correct |
9 ms |
3112 KB |
Output is correct |
7 |
Correct |
9 ms |
3024 KB |
Output is correct |
8 |
Correct |
7 ms |
3236 KB |
Output is correct |
9 |
Correct |
11 ms |
3120 KB |
Output is correct |
10 |
Correct |
10 ms |
3152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3140 KB |
Output is correct |
2 |
Correct |
9 ms |
3136 KB |
Output is correct |
3 |
Correct |
11 ms |
3228 KB |
Output is correct |
4 |
Correct |
7 ms |
3248 KB |
Output is correct |
5 |
Correct |
9 ms |
3248 KB |
Output is correct |
6 |
Correct |
7 ms |
3224 KB |
Output is correct |
7 |
Correct |
7 ms |
3160 KB |
Output is correct |
8 |
Correct |
10 ms |
3108 KB |
Output is correct |
9 |
Correct |
7 ms |
3188 KB |
Output is correct |
10 |
Correct |
9 ms |
3152 KB |
Output is correct |
11 |
Correct |
14 ms |
3248 KB |
Output is correct |
12 |
Correct |
10 ms |
3304 KB |
Output is correct |
13 |
Correct |
13 ms |
3244 KB |
Output is correct |
14 |
Correct |
9 ms |
592 KB |
Output is correct |
15 |
Correct |
37 ms |
3400 KB |
Output is correct |
16 |
Correct |
22 ms |
3428 KB |
Output is correct |
17 |
Correct |
31 ms |
3332 KB |
Output is correct |
18 |
Correct |
22 ms |
3432 KB |
Output is correct |
19 |
Correct |
39 ms |
3412 KB |
Output is correct |
20 |
Correct |
32 ms |
1864 KB |
Output is correct |
21 |
Correct |
46 ms |
3340 KB |
Output is correct |
22 |
Correct |
29 ms |
3408 KB |
Output is correct |
23 |
Correct |
10 ms |
3216 KB |
Output is correct |
24 |
Correct |
8 ms |
3284 KB |
Output is correct |
25 |
Correct |
46 ms |
3404 KB |
Output is correct |
26 |
Correct |
45 ms |
3332 KB |
Output is correct |
27 |
Correct |
11 ms |
3144 KB |
Output is correct |
28 |
Correct |
21 ms |
3436 KB |
Output is correct |
29 |
Correct |
31 ms |
3400 KB |
Output is correct |
30 |
Correct |
43 ms |
3500 KB |
Output is correct |
31 |
Correct |
29 ms |
3372 KB |
Output is correct |
32 |
Correct |
8 ms |
3252 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
29 ms |
3388 KB |
Output is correct |
35 |
Correct |
11 ms |
3280 KB |
Output is correct |
36 |
Correct |
47 ms |
3404 KB |
Output is correct |
37 |
Correct |
13 ms |
3144 KB |
Output is correct |
38 |
Correct |
7 ms |
3256 KB |
Output is correct |
39 |
Correct |
29 ms |
3440 KB |
Output is correct |
40 |
Correct |
34 ms |
3420 KB |
Output is correct |
41 |
Correct |
45 ms |
3420 KB |
Output is correct |
42 |
Correct |
29 ms |
3392 KB |
Output is correct |
43 |
Correct |
47 ms |
3336 KB |
Output is correct |
44 |
Correct |
38 ms |
3408 KB |
Output is correct |
45 |
Correct |
38 ms |
3612 KB |
Output is correct |
46 |
Correct |
48 ms |
3368 KB |
Output is correct |
47 |
Correct |
46 ms |
3428 KB |
Output is correct |
48 |
Correct |
47 ms |
3368 KB |
Output is correct |
49 |
Correct |
37 ms |
3436 KB |
Output is correct |
50 |
Correct |
46 ms |
3340 KB |
Output is correct |
51 |
Correct |
26 ms |
3440 KB |
Output is correct |
52 |
Correct |
48 ms |
3368 KB |
Output is correct |
53 |
Correct |
8 ms |
3256 KB |
Output is correct |
54 |
Correct |
40 ms |
3412 KB |
Output is correct |
55 |
Correct |
22 ms |
3452 KB |
Output is correct |
56 |
Correct |
44 ms |
3400 KB |
Output is correct |
57 |
Correct |
36 ms |
3380 KB |
Output is correct |
58 |
Correct |
24 ms |
3460 KB |
Output is correct |
59 |
Correct |
46 ms |
3344 KB |
Output is correct |
60 |
Correct |
33 ms |
3432 KB |
Output is correct |
61 |
Correct |
8 ms |
3280 KB |
Output is correct |
62 |
Correct |
8 ms |
3248 KB |
Output is correct |
63 |
Correct |
10 ms |
3152 KB |
Output is correct |
64 |
Correct |
10 ms |
3144 KB |
Output is correct |
65 |
Correct |
10 ms |
3164 KB |
Output is correct |
66 |
Correct |
16 ms |
3112 KB |
Output is correct |
67 |
Correct |
13 ms |
3216 KB |
Output is correct |
68 |
Correct |
13 ms |
3152 KB |
Output is correct |
69 |
Correct |
9 ms |
3220 KB |
Output is correct |
70 |
Correct |
14 ms |
3332 KB |
Output is correct |
71 |
Partially correct |
37 ms |
3404 KB |
Partially correct - number of queries: 5142 |
72 |
Correct |
13 ms |
3308 KB |
Output is correct |
73 |
Partially correct |
48 ms |
3316 KB |
Partially correct - number of queries: 5075 |
74 |
Partially correct |
41 ms |
3444 KB |
Partially correct - number of queries: 5122 |
75 |
Correct |
12 ms |
3232 KB |
Output is correct |
76 |
Correct |
33 ms |
3384 KB |
Output is correct |
77 |
Partially correct |
50 ms |
3412 KB |
Partially correct - number of queries: 5023 |
78 |
Correct |
12 ms |
3396 KB |
Output is correct |
79 |
Correct |
15 ms |
3412 KB |
Output is correct |
80 |
Partially correct |
36 ms |
3352 KB |
Partially correct - number of queries: 5003 |
81 |
Partially correct |
51 ms |
3400 KB |
Partially correct - number of queries: 5006 |
82 |
Correct |
49 ms |
3396 KB |
Output is correct |
83 |
Correct |
10 ms |
3168 KB |
Output is correct |
84 |
Correct |
31 ms |
3352 KB |
Output is correct |
85 |
Partially correct |
43 ms |
3376 KB |
Partially correct - number of queries: 5013 |
86 |
Correct |
35 ms |
3364 KB |
Output is correct |
87 |
Correct |
11 ms |
3280 KB |
Output is correct |
88 |
Correct |
35 ms |
3380 KB |
Output is correct |
89 |
Correct |
45 ms |
3316 KB |
Output is correct |
90 |
Correct |
9 ms |
3144 KB |
Output is correct |
91 |
Correct |
24 ms |
3412 KB |
Output is correct |
92 |
Correct |
35 ms |
3420 KB |
Output is correct |
93 |
Correct |
53 ms |
3352 KB |
Output is correct |
94 |
Correct |
44 ms |
3380 KB |
Output is correct |
95 |
Correct |
21 ms |
3420 KB |
Output is correct |
96 |
Correct |
27 ms |
3516 KB |
Output is correct |
97 |
Correct |
51 ms |
3332 KB |
Output is correct |