#include "prize.h"
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define big 4172398721
#define MOD 1000000007
using namespace std;
#define pii pair<int, int>
#ifdef wiwihorz
#define print(a...) cerr << "Line: " << __LINE__, kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
int x;
random;
map<int, pii> mp;
pii Ask(int x) {
if(mp.find(x) == mp.end()) {
vector<int> v;
v = ask(x);
mp[x] = {v[0], v[1]};
}
return mp[x];
}
int solve(int L, int R, int tot, int pre) {
// print(L, R, tot, pre);
if(L == R) {
pii p = Ask(L);
return (p.first + p.second ? -1 : L);
}
int mid = (L + R) / 2, piv = -1, ans = -1;
rep(i, mid + 1, R) {
pii p = Ask(i);
if(p.first + p.second == x) {
piv = i;
break;
}
else ans = max(ans, solve(i, i, 1, 0));
}
if(piv < 0) ans = (tot - (R - mid) ? max(ans, solve(L, mid, tot - (R - mid), pre)) : ans);
else {
pii p = Ask(piv);
int left = p.first - pre - (piv - mid - 1);
int right = tot - p.first + pre;
if(left) ans = max(ans, solve(L, mid, left, pre));
if(right) ans = max(ans, solve(piv, R, right, p.first));
}
return ans;
}
int find_best(int n) {
x = 0;
vector<pii> s;
rrep(i, 0, n - 1) s.push_back({big * rnd() % MOD, i});
sort(all(s));
rep(i, 0, min(473, n) - 1) {
pii p = Ask(s[i].second);
x = max(x, p.first + p.second);
}
return solve(0, n - 1, x, 0);
}
Compilation message
prize.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
5 | #pragma loop-opt(on)
|
prize.cpp:17:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
17 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
| ^~~~
prize.cpp:17:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
17 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2364 KB |
Output is correct |
2 |
Correct |
30 ms |
2364 KB |
Output is correct |
3 |
Correct |
26 ms |
2440 KB |
Output is correct |
4 |
Correct |
30 ms |
2424 KB |
Output is correct |
5 |
Correct |
27 ms |
2452 KB |
Output is correct |
6 |
Correct |
30 ms |
2364 KB |
Output is correct |
7 |
Correct |
28 ms |
2356 KB |
Output is correct |
8 |
Correct |
29 ms |
2356 KB |
Output is correct |
9 |
Correct |
30 ms |
2348 KB |
Output is correct |
10 |
Correct |
31 ms |
2364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2364 KB |
Output is correct |
2 |
Correct |
27 ms |
2364 KB |
Output is correct |
3 |
Correct |
30 ms |
2364 KB |
Output is correct |
4 |
Correct |
28 ms |
2356 KB |
Output is correct |
5 |
Correct |
25 ms |
2448 KB |
Output is correct |
6 |
Correct |
28 ms |
2444 KB |
Output is correct |
7 |
Correct |
28 ms |
2440 KB |
Output is correct |
8 |
Correct |
26 ms |
2440 KB |
Output is correct |
9 |
Correct |
29 ms |
2492 KB |
Output is correct |
10 |
Correct |
26 ms |
2364 KB |
Output is correct |
11 |
Correct |
32 ms |
2364 KB |
Output is correct |
12 |
Correct |
29 ms |
2484 KB |
Output is correct |
13 |
Correct |
30 ms |
2484 KB |
Output is correct |
14 |
Correct |
19 ms |
584 KB |
Output is correct |
15 |
Correct |
71 ms |
2364 KB |
Output is correct |
16 |
Correct |
66 ms |
2364 KB |
Output is correct |
17 |
Correct |
75 ms |
2456 KB |
Output is correct |
18 |
Correct |
78 ms |
2452 KB |
Output is correct |
19 |
Correct |
63 ms |
2444 KB |
Output is correct |
20 |
Correct |
30 ms |
1472 KB |
Output is correct |
21 |
Correct |
48 ms |
2444 KB |
Output is correct |
22 |
Correct |
44 ms |
2440 KB |
Output is correct |
23 |
Correct |
31 ms |
2452 KB |
Output is correct |
24 |
Correct |
28 ms |
2364 KB |
Output is correct |
25 |
Correct |
64 ms |
2364 KB |
Output is correct |
26 |
Correct |
59 ms |
2356 KB |
Output is correct |
27 |
Correct |
26 ms |
2484 KB |
Output is correct |
28 |
Correct |
68 ms |
2440 KB |
Output is correct |
29 |
Correct |
62 ms |
2364 KB |
Output is correct |
30 |
Correct |
49 ms |
2484 KB |
Output is correct |
31 |
Correct |
76 ms |
2356 KB |
Output is correct |
32 |
Correct |
33 ms |
2444 KB |
Output is correct |
33 |
Correct |
1 ms |
200 KB |
Output is correct |
34 |
Correct |
66 ms |
2432 KB |
Output is correct |
35 |
Correct |
30 ms |
2452 KB |
Output is correct |
36 |
Correct |
50 ms |
2432 KB |
Output is correct |
37 |
Correct |
35 ms |
2448 KB |
Output is correct |
38 |
Correct |
26 ms |
2420 KB |
Output is correct |
39 |
Correct |
48 ms |
2484 KB |
Output is correct |
40 |
Correct |
69 ms |
2364 KB |
Output is correct |
41 |
Correct |
80 ms |
2484 KB |
Output is correct |
42 |
Correct |
56 ms |
2456 KB |
Output is correct |
43 |
Correct |
80 ms |
2492 KB |
Output is correct |
44 |
Correct |
76 ms |
2448 KB |
Output is correct |
45 |
Correct |
69 ms |
2356 KB |
Output is correct |
46 |
Correct |
64 ms |
2356 KB |
Output is correct |
47 |
Correct |
71 ms |
2356 KB |
Output is correct |
48 |
Correct |
85 ms |
2456 KB |
Output is correct |
49 |
Correct |
89 ms |
2364 KB |
Output is correct |
50 |
Correct |
67 ms |
2440 KB |
Output is correct |
51 |
Correct |
83 ms |
2364 KB |
Output is correct |
52 |
Correct |
72 ms |
2364 KB |
Output is correct |
53 |
Correct |
31 ms |
2356 KB |
Output is correct |
54 |
Correct |
66 ms |
2448 KB |
Output is correct |
55 |
Correct |
78 ms |
2444 KB |
Output is correct |
56 |
Correct |
51 ms |
2448 KB |
Output is correct |
57 |
Correct |
65 ms |
2444 KB |
Output is correct |
58 |
Correct |
81 ms |
2440 KB |
Output is correct |
59 |
Correct |
73 ms |
2444 KB |
Output is correct |
60 |
Correct |
47 ms |
2492 KB |
Output is correct |
61 |
Correct |
26 ms |
2448 KB |
Output is correct |
62 |
Correct |
30 ms |
2452 KB |
Output is correct |
63 |
Correct |
31 ms |
2356 KB |
Output is correct |
64 |
Correct |
37 ms |
2428 KB |
Output is correct |
65 |
Correct |
27 ms |
2356 KB |
Output is correct |
66 |
Correct |
32 ms |
2356 KB |
Output is correct |
67 |
Correct |
34 ms |
2356 KB |
Output is correct |
68 |
Correct |
30 ms |
2452 KB |
Output is correct |
69 |
Correct |
32 ms |
2364 KB |
Output is correct |
70 |
Correct |
33 ms |
2364 KB |
Output is correct |
71 |
Partially correct |
80 ms |
2364 KB |
Partially correct - number of queries: 5212 |
72 |
Correct |
29 ms |
2364 KB |
Output is correct |
73 |
Partially correct |
83 ms |
2364 KB |
Partially correct - number of queries: 5149 |
74 |
Partially correct |
53 ms |
2364 KB |
Partially correct - number of queries: 5174 |
75 |
Correct |
30 ms |
2364 KB |
Output is correct |
76 |
Correct |
73 ms |
2492 KB |
Output is correct |
77 |
Correct |
85 ms |
2492 KB |
Output is correct |
78 |
Correct |
34 ms |
2364 KB |
Output is correct |
79 |
Correct |
56 ms |
2364 KB |
Output is correct |
80 |
Correct |
79 ms |
2364 KB |
Output is correct |
81 |
Correct |
50 ms |
2456 KB |
Output is correct |
82 |
Correct |
78 ms |
2364 KB |
Output is correct |
83 |
Correct |
30 ms |
2364 KB |
Output is correct |
84 |
Correct |
56 ms |
2492 KB |
Output is correct |
85 |
Correct |
83 ms |
2364 KB |
Output is correct |
86 |
Correct |
60 ms |
2364 KB |
Output is correct |
87 |
Correct |
33 ms |
2364 KB |
Output is correct |
88 |
Correct |
61 ms |
2364 KB |
Output is correct |
89 |
Correct |
66 ms |
2364 KB |
Output is correct |
90 |
Correct |
30 ms |
2492 KB |
Output is correct |
91 |
Correct |
55 ms |
2364 KB |
Output is correct |
92 |
Correct |
65 ms |
2364 KB |
Output is correct |
93 |
Correct |
44 ms |
2364 KB |
Output is correct |
94 |
Correct |
52 ms |
2364 KB |
Output is correct |
95 |
Correct |
64 ms |
2492 KB |
Output is correct |
96 |
Correct |
57 ms |
2492 KB |
Output is correct |
97 |
Correct |
73 ms |
2364 KB |
Output is correct |