#pragma GCC optimize ("O3")
#include "prize.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int up = 2e5 + 5;
int okay = 0;
vi cnt[up];
vi ASK(int i) {
if (cnt[i][0] != oo) return cnt[i];
else return ask(i);
}
void solve(int l, int r, int subL, int subR) {
if (l <= r) {
int mid = (l + r) >> 1;
vi a = ASK(mid);
if (a[0] + a[1] < okay) { /// not last type
int lmid = mid - 1, rmid = mid + 1;
cnt[mid] = a;
while (lmid >= l) {
a = ASK(lmid);
if (a[0] + a[1] < okay) {
cnt[lmid] = a;
--lmid;
} else {
break;
}
}
if (a[0] - subL > 0 && lmid > l) {
solve(l, lmid - 1, subL, a[1]);
}
while (rmid <= r) {
a = ASK(rmid);
if (a[0] + a[1] < okay) {
cnt[rmid] = a;
++rmid;
} else {
break;
}
}
if (a[1] - subR > 0 && rmid < r) {
solve(rmid + 1, r, a[0], subR);
}
} else { /// last type
if (a[0] - subL > 0) {
solve(l, mid - 1, subL, a[1]);
}
if (a[1] - subR > 0) {
solve(mid + 1, r, a[0], subR);
}
}
}
}
int find_best(int n) {
vi p(n);
for (int i = 0; i < n; ++i) {
p[i] = i;
cnt[i] = {oo, oo};
}
shuffle(all(p), rng);
for (int i = 0; i < n && i < 473; ++i) { /// type_cnt[1, 4, 21, 446, last] 1 + 4 + 21 + 446 = 472
cnt[p[i]] = ASK(p[i]);
okay = max(okay, cnt[p[i]][0] + cnt[p[i]][1]);
if (okay > 26) break; /// 1 + 4 + 21 = 26
}
solve(0, n - 1, 0, 0);
for (int i = 0; i < n; ++i) {
if (cnt[i][0] + cnt[i][1] == 0) return i;
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:77:9: warning: control reaches end of non-void function [-Wreturn-type]
77 | vi p(n);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
12024 KB |
Output is correct |
2 |
Correct |
22 ms |
11976 KB |
Output is correct |
3 |
Correct |
20 ms |
11984 KB |
Output is correct |
4 |
Correct |
20 ms |
12056 KB |
Output is correct |
5 |
Correct |
17 ms |
12056 KB |
Output is correct |
6 |
Correct |
24 ms |
12040 KB |
Output is correct |
7 |
Correct |
20 ms |
12024 KB |
Output is correct |
8 |
Correct |
20 ms |
12028 KB |
Output is correct |
9 |
Correct |
17 ms |
12036 KB |
Output is correct |
10 |
Correct |
22 ms |
12060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
12040 KB |
Output is correct |
2 |
Correct |
23 ms |
11940 KB |
Output is correct |
3 |
Correct |
21 ms |
12036 KB |
Output is correct |
4 |
Correct |
20 ms |
12048 KB |
Output is correct |
5 |
Correct |
22 ms |
12060 KB |
Output is correct |
6 |
Correct |
24 ms |
12044 KB |
Output is correct |
7 |
Correct |
23 ms |
11984 KB |
Output is correct |
8 |
Correct |
20 ms |
12044 KB |
Output is correct |
9 |
Correct |
24 ms |
12044 KB |
Output is correct |
10 |
Correct |
20 ms |
12068 KB |
Output is correct |
11 |
Correct |
19 ms |
12032 KB |
Output is correct |
12 |
Correct |
20 ms |
12036 KB |
Output is correct |
13 |
Correct |
24 ms |
11984 KB |
Output is correct |
14 |
Correct |
15 ms |
5712 KB |
Output is correct |
15 |
Correct |
54 ms |
12024 KB |
Output is correct |
16 |
Correct |
58 ms |
12036 KB |
Output is correct |
17 |
Correct |
62 ms |
12048 KB |
Output is correct |
18 |
Correct |
59 ms |
12036 KB |
Output is correct |
19 |
Correct |
54 ms |
12048 KB |
Output is correct |
20 |
Correct |
45 ms |
8452 KB |
Output is correct |
21 |
Correct |
49 ms |
11976 KB |
Output is correct |
22 |
Correct |
29 ms |
12144 KB |
Output is correct |
23 |
Correct |
23 ms |
12024 KB |
Output is correct |
24 |
Correct |
19 ms |
11984 KB |
Output is correct |
25 |
Correct |
59 ms |
12040 KB |
Output is correct |
26 |
Correct |
56 ms |
12024 KB |
Output is correct |
27 |
Correct |
21 ms |
11984 KB |
Output is correct |
28 |
Correct |
56 ms |
11972 KB |
Output is correct |
29 |
Correct |
40 ms |
12032 KB |
Output is correct |
30 |
Correct |
35 ms |
12064 KB |
Output is correct |
31 |
Correct |
61 ms |
12036 KB |
Output is correct |
32 |
Correct |
25 ms |
12028 KB |
Output is correct |
33 |
Correct |
4 ms |
4944 KB |
Output is correct |
34 |
Correct |
50 ms |
12032 KB |
Output is correct |
35 |
Correct |
19 ms |
12040 KB |
Output is correct |
36 |
Correct |
65 ms |
11976 KB |
Output is correct |
37 |
Correct |
18 ms |
11976 KB |
Output is correct |
38 |
Correct |
24 ms |
12020 KB |
Output is correct |
39 |
Correct |
55 ms |
12032 KB |
Output is correct |
40 |
Correct |
56 ms |
12028 KB |
Output is correct |
41 |
Correct |
53 ms |
12036 KB |
Output is correct |
42 |
Correct |
43 ms |
12108 KB |
Output is correct |
43 |
Correct |
40 ms |
12032 KB |
Output is correct |
44 |
Correct |
51 ms |
12040 KB |
Output is correct |
45 |
Correct |
40 ms |
12048 KB |
Output is correct |
46 |
Correct |
59 ms |
12028 KB |
Output is correct |
47 |
Correct |
34 ms |
12052 KB |
Output is correct |
48 |
Correct |
62 ms |
11976 KB |
Output is correct |
49 |
Correct |
62 ms |
12016 KB |
Output is correct |
50 |
Correct |
57 ms |
11980 KB |
Output is correct |
51 |
Correct |
60 ms |
11976 KB |
Output is correct |
52 |
Correct |
60 ms |
12040 KB |
Output is correct |
53 |
Correct |
21 ms |
11976 KB |
Output is correct |
54 |
Correct |
46 ms |
12040 KB |
Output is correct |
55 |
Correct |
59 ms |
11992 KB |
Output is correct |
56 |
Correct |
34 ms |
12040 KB |
Output is correct |
57 |
Correct |
35 ms |
12036 KB |
Output is correct |
58 |
Correct |
62 ms |
12032 KB |
Output is correct |
59 |
Correct |
53 ms |
12036 KB |
Output is correct |
60 |
Correct |
32 ms |
12060 KB |
Output is correct |
61 |
Correct |
25 ms |
12028 KB |
Output is correct |
62 |
Correct |
20 ms |
11984 KB |
Output is correct |
63 |
Correct |
20 ms |
11984 KB |
Output is correct |
64 |
Correct |
17 ms |
12004 KB |
Output is correct |
65 |
Correct |
15 ms |
12028 KB |
Output is correct |
66 |
Correct |
22 ms |
12024 KB |
Output is correct |
67 |
Correct |
18 ms |
12056 KB |
Output is correct |
68 |
Correct |
19 ms |
11976 KB |
Output is correct |
69 |
Correct |
23 ms |
11984 KB |
Output is correct |
70 |
Correct |
19 ms |
12028 KB |
Output is correct |
71 |
Correct |
54 ms |
11984 KB |
Output is correct |
72 |
Correct |
19 ms |
12052 KB |
Output is correct |
73 |
Correct |
61 ms |
11984 KB |
Output is correct |
74 |
Correct |
66 ms |
12060 KB |
Output is correct |
75 |
Correct |
22 ms |
12048 KB |
Output is correct |
76 |
Correct |
60 ms |
12064 KB |
Output is correct |
77 |
Correct |
47 ms |
11984 KB |
Output is correct |
78 |
Correct |
19 ms |
11984 KB |
Output is correct |
79 |
Correct |
45 ms |
11952 KB |
Output is correct |
80 |
Correct |
40 ms |
12056 KB |
Output is correct |
81 |
Correct |
47 ms |
12052 KB |
Output is correct |
82 |
Correct |
57 ms |
11984 KB |
Output is correct |
83 |
Correct |
21 ms |
11984 KB |
Output is correct |
84 |
Correct |
61 ms |
11984 KB |
Output is correct |
85 |
Correct |
68 ms |
12052 KB |
Output is correct |
86 |
Correct |
39 ms |
11984 KB |
Output is correct |
87 |
Correct |
26 ms |
12036 KB |
Output is correct |
88 |
Correct |
25 ms |
12068 KB |
Output is correct |
89 |
Correct |
24 ms |
12044 KB |
Output is correct |
90 |
Correct |
25 ms |
12044 KB |
Output is correct |
91 |
Correct |
32 ms |
12048 KB |
Output is correct |
92 |
Correct |
35 ms |
11940 KB |
Output is correct |
93 |
Correct |
43 ms |
12064 KB |
Output is correct |
94 |
Correct |
50 ms |
12048 KB |
Output is correct |
95 |
Correct |
77 ms |
11984 KB |
Output is correct |
96 |
Correct |
43 ms |
12048 KB |
Output is correct |
97 |
Correct |
47 ms |
11984 KB |
Output is correct |