#include "prize.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 2e5 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
int n;
vector < int > vec[N];
set < int > st[N];
inline vector < int > Ask(int pos)
{
if(!vec[pos].empty())
{
return vec[pos];
}
return vec[pos] = ask(pos);
}
int solve(int l, int r)
{
if(l > r) return -1;
int mid = (l + r) >> 1;
int s = Ask(mid)[0] + Ask(mid)[1];
if(!s) return mid;
auto it = st[s].lower_bound(mid);
int L = 0, R = 0;
if(it == st[s].begin() || Ask(mid)[0] != Ask(*prev(it))[0])
{
L = 1;
}
if(it == st[s].end() || Ask(mid)[1] != Ask(*it)[1])
{
R = 1;
}
if(Ask(mid)[0] == 0) L = 0;
if(Ask(mid)[1] == 0) R = 0;
st[s].insert(mid);
if(L)
{
int ret = solve(l, mid - 1);
if(ret != -1) return ret;
}
if(R)
{
int ret = solve(mid + 1, r);
if(ret != -1) return ret;
}
return -1;
}
int find_best(int _n)
{
n = _n;
return solve(0, n - 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14380 KB |
Output is correct |
4 |
Correct |
11 ms |
14380 KB |
Output is correct |
5 |
Correct |
9 ms |
14332 KB |
Output is correct |
6 |
Correct |
8 ms |
14380 KB |
Output is correct |
7 |
Correct |
10 ms |
14380 KB |
Output is correct |
8 |
Correct |
9 ms |
14384 KB |
Output is correct |
9 |
Correct |
10 ms |
14384 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14384 KB |
Output is correct |
2 |
Correct |
10 ms |
14388 KB |
Output is correct |
3 |
Correct |
10 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
9 ms |
14380 KB |
Output is correct |
6 |
Correct |
10 ms |
14384 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
8 |
Correct |
8 ms |
14380 KB |
Output is correct |
9 |
Correct |
9 ms |
14408 KB |
Output is correct |
10 |
Correct |
10 ms |
14388 KB |
Output is correct |
11 |
Correct |
12 ms |
14380 KB |
Output is correct |
12 |
Correct |
10 ms |
14288 KB |
Output is correct |
13 |
Correct |
13 ms |
14408 KB |
Output is correct |
14 |
Correct |
10 ms |
14288 KB |
Output is correct |
15 |
Correct |
13 ms |
14416 KB |
Output is correct |
16 |
Correct |
28 ms |
14640 KB |
Output is correct |
17 |
Correct |
11 ms |
14384 KB |
Output is correct |
18 |
Correct |
60 ms |
14628 KB |
Output is correct |
19 |
Correct |
9 ms |
14380 KB |
Output is correct |
20 |
Correct |
13 ms |
14476 KB |
Output is correct |
21 |
Correct |
31 ms |
14500 KB |
Output is correct |
22 |
Correct |
15 ms |
14288 KB |
Output is correct |
23 |
Correct |
9 ms |
14380 KB |
Output is correct |
24 |
Correct |
8 ms |
14288 KB |
Output is correct |
25 |
Correct |
33 ms |
14504 KB |
Output is correct |
26 |
Correct |
19 ms |
14548 KB |
Output is correct |
27 |
Correct |
11 ms |
14392 KB |
Output is correct |
28 |
Correct |
46 ms |
14660 KB |
Output is correct |
29 |
Correct |
34 ms |
14500 KB |
Output is correct |
30 |
Correct |
48 ms |
14624 KB |
Output is correct |
31 |
Correct |
9 ms |
14376 KB |
Output is correct |
32 |
Correct |
11 ms |
14408 KB |
Output is correct |
33 |
Correct |
8 ms |
14288 KB |
Output is correct |
34 |
Correct |
21 ms |
14420 KB |
Output is correct |
35 |
Correct |
9 ms |
14384 KB |
Output is correct |
36 |
Correct |
18 ms |
14376 KB |
Output is correct |
37 |
Correct |
9 ms |
14288 KB |
Output is correct |
38 |
Correct |
9 ms |
14376 KB |
Output is correct |
39 |
Correct |
19 ms |
14480 KB |
Output is correct |
40 |
Correct |
46 ms |
14664 KB |
Output is correct |
41 |
Correct |
23 ms |
14660 KB |
Output is correct |
42 |
Correct |
37 ms |
14500 KB |
Output is correct |
43 |
Correct |
29 ms |
14588 KB |
Output is correct |
44 |
Correct |
31 ms |
14500 KB |
Output is correct |
45 |
Correct |
26 ms |
14416 KB |
Output is correct |
46 |
Correct |
8 ms |
14288 KB |
Output is correct |
47 |
Correct |
22 ms |
14504 KB |
Output is correct |
48 |
Correct |
42 ms |
14632 KB |
Output is correct |
49 |
Correct |
13 ms |
14288 KB |
Output is correct |
50 |
Correct |
58 ms |
14708 KB |
Output is correct |
51 |
Correct |
28 ms |
14448 KB |
Output is correct |
52 |
Correct |
11 ms |
14288 KB |
Output is correct |
53 |
Correct |
10 ms |
14288 KB |
Output is correct |
54 |
Correct |
18 ms |
14496 KB |
Output is correct |
55 |
Correct |
8 ms |
14376 KB |
Output is correct |
56 |
Correct |
56 ms |
14756 KB |
Output is correct |
57 |
Correct |
35 ms |
14548 KB |
Output is correct |
58 |
Correct |
42 ms |
14600 KB |
Output is correct |
59 |
Correct |
30 ms |
14584 KB |
Output is correct |
60 |
Correct |
42 ms |
14568 KB |
Output is correct |
61 |
Correct |
10 ms |
14396 KB |
Output is correct |
62 |
Correct |
11 ms |
14288 KB |
Output is correct |
63 |
Correct |
12 ms |
14288 KB |
Output is correct |
64 |
Correct |
9 ms |
14364 KB |
Output is correct |
65 |
Correct |
8 ms |
14288 KB |
Output is correct |
66 |
Correct |
9 ms |
14288 KB |
Output is correct |
67 |
Correct |
8 ms |
14384 KB |
Output is correct |
68 |
Correct |
11 ms |
14264 KB |
Output is correct |
69 |
Correct |
9 ms |
14288 KB |
Output is correct |
70 |
Correct |
8 ms |
14288 KB |
Output is correct |
71 |
Correct |
53 ms |
14704 KB |
Output is correct |
72 |
Correct |
13 ms |
14416 KB |
Output is correct |
73 |
Correct |
59 ms |
14724 KB |
Output is correct |
74 |
Correct |
57 ms |
14612 KB |
Output is correct |
75 |
Correct |
10 ms |
14288 KB |
Output is correct |
76 |
Correct |
55 ms |
14672 KB |
Output is correct |
77 |
Correct |
63 ms |
14672 KB |
Output is correct |
78 |
Correct |
13 ms |
14416 KB |
Output is correct |
79 |
Correct |
31 ms |
14600 KB |
Output is correct |
80 |
Correct |
57 ms |
14760 KB |
Output is correct |
81 |
Correct |
61 ms |
14716 KB |
Output is correct |
82 |
Correct |
63 ms |
14628 KB |
Output is correct |
83 |
Correct |
10 ms |
14288 KB |
Output is correct |
84 |
Correct |
43 ms |
14660 KB |
Output is correct |
85 |
Correct |
65 ms |
14696 KB |
Output is correct |
86 |
Correct |
14 ms |
14416 KB |
Output is correct |
87 |
Correct |
10 ms |
14288 KB |
Output is correct |
88 |
Correct |
15 ms |
14416 KB |
Output is correct |
89 |
Correct |
15 ms |
14416 KB |
Output is correct |
90 |
Correct |
9 ms |
14396 KB |
Output is correct |
91 |
Correct |
11 ms |
14416 KB |
Output is correct |
92 |
Correct |
10 ms |
14296 KB |
Output is correct |
93 |
Correct |
11 ms |
14288 KB |
Output is correct |
94 |
Correct |
12 ms |
14416 KB |
Output is correct |
95 |
Correct |
14 ms |
14288 KB |
Output is correct |
96 |
Correct |
11 ms |
14340 KB |
Output is correct |
97 |
Correct |
8 ms |
14288 KB |
Output is correct |