#include "prize.h"
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int maxn = 200100;
bool visited[maxn];
int q[maxn][2];
int max_sum, ind;
P query(int i) {
if(visited[i]) return {q[i][0], q[i][1]};
visited[i] = true;
vector<int>curr = ask(i);
q[i][0] = curr[0];
q[i][1] = curr[1];
return {q[i][0], q[i][1]};
}
int sum(int i) {
query(i);
return q[i][0] + q[i][1];
}
void solve(int l, int r) {
//cout<<l<<" "<<r<<"\n";
if(l > r || ind != -1) return;
P ql = query(l);
P qr = query(r);
int suml = ql.first + ql.second;
int sumr = qr.first + qr.second;
if(suml == 0) {
ind = l;
return;
}
if(sumr == 0) {
ind = r;
return;
}
if(ql.second == 0 || qr.first == 0) return;
if(l == r) return;
if(suml != max_sum) {
solve(l+1, r);
return;
}
if(sumr != max_sum) {
solve(l, r-1);
return;
}
int between = qr.first - ql.first;
if(between == 0) return;
int mid = (l + r) / 2;
solve(l, mid);
solve(mid, r);
}
int find_best(int n) {
ind = -1;
int b = sqrt(n) + 1;
b = min(n, b);
mt19937 g(chrono::high_resolution_clock::now().time_since_epoch().count());
uniform_int_distribution<int> uid(0, n - 1);
for(int i=0;i-b<n;i+=b) {
int x = min(i, n-1);
if(sum(x) == 0) return x;
max_sum = max(max_sum, sum(x));
} //max_sum = 1;
/*for(int i=0;i<100;i++) {
int pos = uid(g);
if(sum(pos) == 0) return pos;
max_sum = max(max_sum, sum(pos));
}*/
for(int l=0;l<n;l+=b) {
int r = min(n-1, l+b-1);
solve(l, r);
}
return ind;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1976 KB |
Output is correct |
2 |
Correct |
10 ms |
2040 KB |
Output is correct |
3 |
Correct |
11 ms |
2048 KB |
Output is correct |
4 |
Correct |
6 ms |
2040 KB |
Output is correct |
5 |
Correct |
9 ms |
2040 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
2040 KB |
Output is correct |
8 |
Correct |
8 ms |
2040 KB |
Output is correct |
9 |
Correct |
12 ms |
2040 KB |
Output is correct |
10 |
Correct |
6 ms |
2080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2164 KB |
Output is correct |
2 |
Correct |
7 ms |
1960 KB |
Output is correct |
3 |
Correct |
8 ms |
2096 KB |
Output is correct |
4 |
Correct |
10 ms |
2040 KB |
Output is correct |
5 |
Correct |
9 ms |
2040 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
2064 KB |
Output is correct |
8 |
Correct |
7 ms |
2068 KB |
Output is correct |
9 |
Correct |
6 ms |
2164 KB |
Output is correct |
10 |
Correct |
9 ms |
2048 KB |
Output is correct |
11 |
Correct |
8 ms |
2148 KB |
Output is correct |
12 |
Correct |
7 ms |
2040 KB |
Output is correct |
13 |
Correct |
14 ms |
2040 KB |
Output is correct |
14 |
Correct |
3 ms |
456 KB |
Output is correct |
15 |
Correct |
12 ms |
2040 KB |
Output is correct |
16 |
Correct |
38 ms |
2012 KB |
Output is correct |
17 |
Correct |
4 ms |
2172 KB |
Output is correct |
18 |
Partially correct |
18 ms |
2036 KB |
Partially correct - number of queries: 5025 |
19 |
Correct |
5 ms |
2036 KB |
Output is correct |
20 |
Correct |
11 ms |
1144 KB |
Output is correct |
21 |
Correct |
10 ms |
2036 KB |
Output is correct |
22 |
Correct |
8 ms |
2040 KB |
Output is correct |
23 |
Correct |
6 ms |
2040 KB |
Output is correct |
24 |
Correct |
7 ms |
2040 KB |
Output is correct |
25 |
Correct |
24 ms |
2040 KB |
Output is correct |
26 |
Correct |
27 ms |
2040 KB |
Output is correct |
27 |
Correct |
7 ms |
2040 KB |
Output is correct |
28 |
Correct |
17 ms |
2036 KB |
Output is correct |
29 |
Correct |
34 ms |
2040 KB |
Output is correct |
30 |
Correct |
58 ms |
1976 KB |
Output is correct |
31 |
Correct |
7 ms |
2040 KB |
Output is correct |
32 |
Correct |
6 ms |
2032 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
19 ms |
2040 KB |
Output is correct |
35 |
Correct |
6 ms |
2172 KB |
Output is correct |
36 |
Correct |
8 ms |
1980 KB |
Output is correct |
37 |
Correct |
5 ms |
2036 KB |
Output is correct |
38 |
Correct |
5 ms |
2164 KB |
Output is correct |
39 |
Correct |
29 ms |
2040 KB |
Output is correct |
40 |
Correct |
18 ms |
1972 KB |
Output is correct |
41 |
Correct |
13 ms |
2040 KB |
Output is correct |
42 |
Correct |
38 ms |
2040 KB |
Output is correct |
43 |
Correct |
20 ms |
2044 KB |
Output is correct |
44 |
Correct |
13 ms |
2084 KB |
Output is correct |
45 |
Correct |
15 ms |
2040 KB |
Output is correct |
46 |
Correct |
9 ms |
1972 KB |
Output is correct |
47 |
Correct |
9 ms |
2036 KB |
Output is correct |
48 |
Correct |
26 ms |
2040 KB |
Output is correct |
49 |
Correct |
5 ms |
2056 KB |
Output is correct |
50 |
Correct |
48 ms |
1972 KB |
Output is correct |
51 |
Correct |
28 ms |
2040 KB |
Output is correct |
52 |
Correct |
9 ms |
2040 KB |
Output is correct |
53 |
Correct |
10 ms |
2040 KB |
Output is correct |
54 |
Correct |
10 ms |
2036 KB |
Output is correct |
55 |
Correct |
6 ms |
2040 KB |
Output is correct |
56 |
Partially correct |
41 ms |
2040 KB |
Partially correct - number of queries: 5049 |
57 |
Correct |
14 ms |
1968 KB |
Output is correct |
58 |
Correct |
14 ms |
1980 KB |
Output is correct |
59 |
Correct |
31 ms |
1956 KB |
Output is correct |
60 |
Correct |
26 ms |
2040 KB |
Output is correct |
61 |
Correct |
11 ms |
2040 KB |
Output is correct |
62 |
Correct |
8 ms |
2040 KB |
Output is correct |
63 |
Correct |
11 ms |
2040 KB |
Output is correct |
64 |
Correct |
5 ms |
2036 KB |
Output is correct |
65 |
Correct |
9 ms |
2040 KB |
Output is correct |
66 |
Correct |
6 ms |
2036 KB |
Output is correct |
67 |
Correct |
11 ms |
2040 KB |
Output is correct |
68 |
Correct |
8 ms |
2040 KB |
Output is correct |
69 |
Correct |
10 ms |
1972 KB |
Output is correct |
70 |
Correct |
6 ms |
2036 KB |
Output is correct |
71 |
Partially correct |
31 ms |
2048 KB |
Partially correct - number of queries: 5116 |
72 |
Correct |
15 ms |
2048 KB |
Output is correct |
73 |
Partially correct |
33 ms |
2048 KB |
Partially correct - number of queries: 5060 |
74 |
Partially correct |
32 ms |
2048 KB |
Partially correct - number of queries: 5084 |
75 |
Correct |
11 ms |
2048 KB |
Output is correct |
76 |
Correct |
43 ms |
2048 KB |
Output is correct |
77 |
Partially correct |
50 ms |
2048 KB |
Partially correct - number of queries: 5104 |
78 |
Correct |
7 ms |
2188 KB |
Output is correct |
79 |
Correct |
24 ms |
2048 KB |
Output is correct |
80 |
Partially correct |
30 ms |
2048 KB |
Partially correct - number of queries: 5096 |
81 |
Partially correct |
19 ms |
2060 KB |
Partially correct - number of queries: 5028 |
82 |
Partially correct |
18 ms |
2080 KB |
Partially correct - number of queries: 5026 |
83 |
Correct |
11 ms |
2048 KB |
Output is correct |
84 |
Correct |
33 ms |
2040 KB |
Output is correct |
85 |
Partially correct |
36 ms |
2048 KB |
Partially correct - number of queries: 5109 |
86 |
Correct |
14 ms |
1988 KB |
Output is correct |
87 |
Correct |
6 ms |
2072 KB |
Output is correct |
88 |
Correct |
15 ms |
2048 KB |
Output is correct |
89 |
Correct |
11 ms |
2048 KB |
Output is correct |
90 |
Correct |
10 ms |
2048 KB |
Output is correct |
91 |
Correct |
12 ms |
2048 KB |
Output is correct |
92 |
Correct |
7 ms |
2100 KB |
Output is correct |
93 |
Correct |
11 ms |
2048 KB |
Output is correct |
94 |
Correct |
20 ms |
2040 KB |
Output is correct |
95 |
Correct |
12 ms |
2048 KB |
Output is correct |
96 |
Correct |
18 ms |
2048 KB |
Output is correct |
97 |
Correct |
17 ms |
2048 KB |
Output is correct |