#include "prize.h"
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 2e5+10;
int l[maxn], r[maxn];
int out = -1;
int maxi = 0;
pair<int,int> query(int x) {
if (l[x] != -1) return {l[x], r[x]};
vector< int > v = ask(x);
l[x] = v[0], r[x] = v[1];
return {l[x], r[x]};
}
void solve(int l, int r) {
if (l > r) return;
if (out != -1) return;
if (query(l).X + query(l).Y == 0) {
out = l;
return;
}
if (query(l).X + query(l).Y < maxi) {solve(l + 1, r); return;}
if (l == r) return;
if (query(r).X + query(r).Y == 0) {
out = r;
return;
}
if (query(r).X + query(r).Y < maxi) {solve(l, r - 1); return;}
if (query(l).X == query(r).X) return;
int mid = (l + r) / 2;
solve(l, mid);
solve(mid, r);
}
int find_best(int n) {
memset(l, -1, sizeof l);
srand(31337);
vector< int > v;
for (int i = 0; i < n; i++) v.push_back(i);
random_shuffle(v.begin(), v.end());
for (int i = 0; i < min(500, n); i++) {
int x = v[i];
pair<int, int> tr = query(x);
if (tr.X + tr.Y == 0) return x;
maxi = max(maxi, tr.X + tr.Y);
}
solve(0, n - 1);
assert(out != -1);
return out;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2672 KB |
Output is correct |
2 |
Correct |
9 ms |
2580 KB |
Output is correct |
3 |
Correct |
8 ms |
2628 KB |
Output is correct |
4 |
Correct |
6 ms |
2652 KB |
Output is correct |
5 |
Correct |
6 ms |
2628 KB |
Output is correct |
6 |
Correct |
6 ms |
2712 KB |
Output is correct |
7 |
Correct |
5 ms |
2676 KB |
Output is correct |
8 |
Correct |
5 ms |
2664 KB |
Output is correct |
9 |
Correct |
8 ms |
2652 KB |
Output is correct |
10 |
Correct |
6 ms |
2660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2656 KB |
Output is correct |
2 |
Correct |
7 ms |
2628 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2712 KB |
Output is correct |
5 |
Correct |
5 ms |
2712 KB |
Output is correct |
6 |
Correct |
7 ms |
2656 KB |
Output is correct |
7 |
Correct |
9 ms |
2692 KB |
Output is correct |
8 |
Correct |
6 ms |
2672 KB |
Output is correct |
9 |
Correct |
7 ms |
2628 KB |
Output is correct |
10 |
Correct |
8 ms |
2628 KB |
Output is correct |
11 |
Correct |
6 ms |
2716 KB |
Output is correct |
12 |
Correct |
9 ms |
2724 KB |
Output is correct |
13 |
Correct |
12 ms |
2720 KB |
Output is correct |
14 |
Correct |
7 ms |
1360 KB |
Output is correct |
15 |
Correct |
14 ms |
2668 KB |
Output is correct |
16 |
Correct |
43 ms |
2652 KB |
Output is correct |
17 |
Correct |
8 ms |
2720 KB |
Output is correct |
18 |
Partially correct |
35 ms |
2724 KB |
Partially correct - number of queries: 5114 |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
16 ms |
1992 KB |
Output is correct |
21 |
Correct |
11 ms |
2752 KB |
Output is correct |
22 |
Correct |
11 ms |
2732 KB |
Output is correct |
23 |
Correct |
9 ms |
2628 KB |
Output is correct |
24 |
Correct |
6 ms |
2676 KB |
Output is correct |
25 |
Correct |
27 ms |
2672 KB |
Output is correct |
26 |
Correct |
13 ms |
2776 KB |
Output is correct |
27 |
Correct |
8 ms |
2620 KB |
Output is correct |
28 |
Correct |
42 ms |
2736 KB |
Output is correct |
29 |
Correct |
16 ms |
2768 KB |
Output is correct |
30 |
Partially correct |
23 ms |
2892 KB |
Partially correct - number of queries: 5086 |
31 |
Correct |
8 ms |
2652 KB |
Output is correct |
32 |
Correct |
9 ms |
2640 KB |
Output is correct |
33 |
Correct |
1 ms |
976 KB |
Output is correct |
34 |
Correct |
10 ms |
2740 KB |
Output is correct |
35 |
Correct |
6 ms |
2744 KB |
Output is correct |
36 |
Correct |
9 ms |
2732 KB |
Output is correct |
37 |
Correct |
8 ms |
2620 KB |
Output is correct |
38 |
Correct |
8 ms |
2628 KB |
Output is correct |
39 |
Correct |
13 ms |
2760 KB |
Output is correct |
40 |
Correct |
44 ms |
2660 KB |
Output is correct |
41 |
Correct |
27 ms |
2720 KB |
Output is correct |
42 |
Correct |
17 ms |
2872 KB |
Output is correct |
43 |
Correct |
27 ms |
2628 KB |
Output is correct |
44 |
Correct |
23 ms |
2720 KB |
Output is correct |
45 |
Correct |
19 ms |
2720 KB |
Output is correct |
46 |
Correct |
8 ms |
2592 KB |
Output is correct |
47 |
Correct |
12 ms |
2744 KB |
Output is correct |
48 |
Correct |
27 ms |
2716 KB |
Output is correct |
49 |
Correct |
8 ms |
2628 KB |
Output is correct |
50 |
Partially correct |
48 ms |
2712 KB |
Partially correct - number of queries: 5124 |
51 |
Correct |
23 ms |
2644 KB |
Output is correct |
52 |
Correct |
9 ms |
2628 KB |
Output is correct |
53 |
Correct |
7 ms |
2708 KB |
Output is correct |
54 |
Correct |
17 ms |
2712 KB |
Output is correct |
55 |
Correct |
6 ms |
2660 KB |
Output is correct |
56 |
Partially correct |
34 ms |
2736 KB |
Partially correct - number of queries: 5092 |
57 |
Correct |
31 ms |
2644 KB |
Output is correct |
58 |
Correct |
24 ms |
2892 KB |
Output is correct |
59 |
Correct |
31 ms |
2720 KB |
Output is correct |
60 |
Correct |
25 ms |
2732 KB |
Output is correct |
61 |
Correct |
8 ms |
2620 KB |
Output is correct |
62 |
Correct |
6 ms |
2680 KB |
Output is correct |
63 |
Correct |
6 ms |
2740 KB |
Output is correct |
64 |
Correct |
6 ms |
2704 KB |
Output is correct |
65 |
Correct |
9 ms |
2644 KB |
Output is correct |
66 |
Correct |
8 ms |
2692 KB |
Output is correct |
67 |
Correct |
12 ms |
2648 KB |
Output is correct |
68 |
Correct |
7 ms |
2676 KB |
Output is correct |
69 |
Correct |
7 ms |
2720 KB |
Output is correct |
70 |
Correct |
7 ms |
2648 KB |
Output is correct |
71 |
Partially correct |
33 ms |
2760 KB |
Partially correct - number of queries: 5229 |
72 |
Correct |
10 ms |
2628 KB |
Output is correct |
73 |
Partially correct |
48 ms |
2728 KB |
Partially correct - number of queries: 5169 |
74 |
Partially correct |
51 ms |
2724 KB |
Partially correct - number of queries: 5195 |
75 |
Correct |
7 ms |
2628 KB |
Output is correct |
76 |
Correct |
41 ms |
2764 KB |
Output is correct |
77 |
Partially correct |
33 ms |
2648 KB |
Partially correct - number of queries: 5206 |
78 |
Correct |
13 ms |
2756 KB |
Output is correct |
79 |
Correct |
21 ms |
2740 KB |
Output is correct |
80 |
Partially correct |
50 ms |
2720 KB |
Partially correct - number of queries: 5172 |
81 |
Partially correct |
48 ms |
2732 KB |
Partially correct - number of queries: 5203 |
82 |
Partially correct |
34 ms |
2764 KB |
Partially correct - number of queries: 5130 |
83 |
Correct |
10 ms |
2628 KB |
Output is correct |
84 |
Correct |
43 ms |
2748 KB |
Output is correct |
85 |
Partially correct |
36 ms |
2736 KB |
Partially correct - number of queries: 5178 |
86 |
Correct |
23 ms |
2728 KB |
Output is correct |
87 |
Correct |
10 ms |
2652 KB |
Output is correct |
88 |
Correct |
26 ms |
2884 KB |
Output is correct |
89 |
Correct |
18 ms |
2728 KB |
Output is correct |
90 |
Correct |
9 ms |
2648 KB |
Output is correct |
91 |
Correct |
14 ms |
2728 KB |
Output is correct |
92 |
Correct |
25 ms |
2628 KB |
Output is correct |
93 |
Correct |
41 ms |
2732 KB |
Output is correct |
94 |
Correct |
40 ms |
2740 KB |
Output is correct |
95 |
Correct |
40 ms |
2732 KB |
Output is correct |
96 |
Correct |
42 ms |
2688 KB |
Output is correct |
97 |
Correct |
31 ms |
2732 KB |
Output is correct |