#include "prize.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
/*vector<int> ask(int i)
{
cout << "? " << i << endl;
vector<int>a(2);
cin >> a[0] >> a[1];
return a;
}*/
int bl = 128;
int find_best(int n)
{
vector<int>a, b;
int mx = 0;
for(int i = 0; i < min(n, 500); i++)
{
a = ask(i);
if(a[0] + a[1] == 0)
return i;
mx = max(mx, a[0] + a[1]);
}
for(int i = 500; i < n; i += bl)
{
int j = min(i + bl - 1, n - 1);
int p = i;
a = ask(p);
while(a[0] + a[1] != mx)
{
if(a[0] + a[1] == 0)
return p;
p++;
if(p > j)
break;
a = ask(p);
}
b = ask(j);
while(b[0] + b[1] != mx)
{
if(b[0] + b[1] == 0)
return j;
j--;
if(j < p)
break;
b = ask(j);
}
if(p < j)
{
int between = b[0] - a[0];
if(between != 0)
{
int it = p + 1;
while(it < j && between > 0)
{
a = ask(it);
if(a[0] + a[1] != mx)
{
between--;
if(a[0] + a[1] == 0)
return it;
}
else
{
int l = it, r = j - 1;
while(l < r)
{
int mid = (l + r) / 2;
b = ask(mid);
if(b[0] + b[1] != mx)
r = mid;
else
{
if(b[0] > a[0])
r = mid - 1;
else
l = mid + 1;
}
}
it = l;
a = ask(it);
--between;
if(a[0] + a[1] == 0)
return it;
}
++it;
}
}
}
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:103:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
376 KB |
Output is correct |
2 |
Correct |
14 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
400 KB |
Output is correct |
4 |
Correct |
38 ms |
376 KB |
Output is correct |
5 |
Correct |
22 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
23 ms |
376 KB |
Output is correct |
8 |
Correct |
20 ms |
248 KB |
Output is correct |
9 |
Correct |
22 ms |
376 KB |
Output is correct |
10 |
Correct |
37 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
26 ms |
308 KB |
Output is correct |
3 |
Correct |
23 ms |
248 KB |
Output is correct |
4 |
Correct |
47 ms |
376 KB |
Output is correct |
5 |
Correct |
12 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
12 ms |
376 KB |
Output is correct |
8 |
Correct |
18 ms |
248 KB |
Output is correct |
9 |
Correct |
26 ms |
248 KB |
Output is correct |
10 |
Correct |
43 ms |
248 KB |
Output is correct |
11 |
Correct |
11 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
396 KB |
Output is correct |
13 |
Correct |
37 ms |
248 KB |
Output is correct |
14 |
Correct |
9 ms |
248 KB |
Output is correct |
15 |
Correct |
17 ms |
376 KB |
Output is correct |
16 |
Partially correct |
69 ms |
248 KB |
Partially correct - number of queries: 6329 |
17 |
Correct |
6 ms |
248 KB |
Output is correct |
18 |
Partially correct |
74 ms |
312 KB |
Partially correct - number of queries: 7519 |
19 |
Correct |
7 ms |
248 KB |
Output is correct |
20 |
Correct |
27 ms |
248 KB |
Output is correct |
21 |
Correct |
17 ms |
312 KB |
Output is correct |
22 |
Correct |
12 ms |
248 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
396 KB |
Output is correct |
25 |
Correct |
55 ms |
376 KB |
Output is correct |
26 |
Correct |
42 ms |
248 KB |
Output is correct |
27 |
Correct |
9 ms |
376 KB |
Output is correct |
28 |
Partially correct |
36 ms |
392 KB |
Partially correct - number of queries: 7127 |
29 |
Partially correct |
66 ms |
248 KB |
Partially correct - number of queries: 5966 |
30 |
Partially correct |
90 ms |
312 KB |
Partially correct - number of queries: 7556 |
31 |
Correct |
7 ms |
248 KB |
Output is correct |
32 |
Correct |
16 ms |
392 KB |
Output is correct |
33 |
Correct |
2 ms |
248 KB |
Output is correct |
34 |
Correct |
15 ms |
308 KB |
Output is correct |
35 |
Correct |
35 ms |
376 KB |
Output is correct |
36 |
Correct |
21 ms |
376 KB |
Output is correct |
37 |
Correct |
15 ms |
248 KB |
Output is correct |
38 |
Correct |
12 ms |
376 KB |
Output is correct |
39 |
Correct |
38 ms |
248 KB |
Output is correct |
40 |
Partially correct |
35 ms |
376 KB |
Partially correct - number of queries: 6936 |
41 |
Correct |
40 ms |
252 KB |
Output is correct |
42 |
Correct |
54 ms |
248 KB |
Output is correct |
43 |
Correct |
40 ms |
248 KB |
Output is correct |
44 |
Correct |
17 ms |
376 KB |
Output is correct |
45 |
Correct |
23 ms |
248 KB |
Output is correct |
46 |
Correct |
4 ms |
396 KB |
Output is correct |
47 |
Correct |
19 ms |
248 KB |
Output is correct |
48 |
Partially correct |
54 ms |
248 KB |
Partially correct - number of queries: 5524 |
49 |
Correct |
12 ms |
316 KB |
Output is correct |
50 |
Partially correct |
74 ms |
312 KB |
Partially correct - number of queries: 7548 |
51 |
Correct |
18 ms |
396 KB |
Output is correct |
52 |
Correct |
8 ms |
248 KB |
Output is correct |
53 |
Correct |
36 ms |
248 KB |
Output is correct |
54 |
Correct |
40 ms |
376 KB |
Output is correct |
55 |
Correct |
4 ms |
376 KB |
Output is correct |
56 |
Partially correct |
82 ms |
396 KB |
Partially correct - number of queries: 7565 |
57 |
Partially correct |
53 ms |
376 KB |
Partially correct - number of queries: 5434 |
58 |
Partially correct |
54 ms |
252 KB |
Partially correct - number of queries: 5517 |
59 |
Correct |
24 ms |
376 KB |
Output is correct |
60 |
Correct |
23 ms |
376 KB |
Output is correct |
61 |
Correct |
25 ms |
376 KB |
Output is correct |
62 |
Correct |
6 ms |
312 KB |
Output is correct |
63 |
Correct |
32 ms |
392 KB |
Output is correct |
64 |
Correct |
27 ms |
376 KB |
Output is correct |
65 |
Correct |
36 ms |
376 KB |
Output is correct |
66 |
Correct |
43 ms |
376 KB |
Output is correct |
67 |
Correct |
30 ms |
404 KB |
Output is correct |
68 |
Correct |
4 ms |
308 KB |
Output is correct |
69 |
Correct |
28 ms |
312 KB |
Output is correct |
70 |
Correct |
40 ms |
248 KB |
Output is correct |
71 |
Partially correct |
75 ms |
248 KB |
Partially correct - number of queries: 7392 |
72 |
Correct |
38 ms |
248 KB |
Output is correct |
73 |
Partially correct |
81 ms |
248 KB |
Partially correct - number of queries: 7336 |
74 |
Partially correct |
86 ms |
376 KB |
Partially correct - number of queries: 7360 |
75 |
Correct |
33 ms |
248 KB |
Output is correct |
76 |
Partially correct |
76 ms |
248 KB |
Partially correct - number of queries: 6816 |
77 |
Partially correct |
70 ms |
380 KB |
Partially correct - number of queries: 7440 |
78 |
Correct |
36 ms |
376 KB |
Output is correct |
79 |
Partially correct |
56 ms |
248 KB |
Partially correct - number of queries: 5347 |
80 |
Partially correct |
74 ms |
248 KB |
Partially correct - number of queries: 7531 |
81 |
Partially correct |
63 ms |
400 KB |
Partially correct - number of queries: 7507 |
82 |
Partially correct |
39 ms |
376 KB |
Partially correct - number of queries: 7458 |
83 |
Correct |
20 ms |
376 KB |
Output is correct |
84 |
Partially correct |
48 ms |
248 KB |
Partially correct - number of queries: 6748 |
85 |
Partially correct |
45 ms |
308 KB |
Partially correct - number of queries: 7525 |
86 |
Correct |
35 ms |
248 KB |
Output is correct |
87 |
Correct |
26 ms |
504 KB |
Output is correct |
88 |
Correct |
35 ms |
248 KB |
Output is correct |
89 |
Correct |
20 ms |
504 KB |
Output is correct |
90 |
Correct |
24 ms |
376 KB |
Output is correct |
91 |
Correct |
43 ms |
376 KB |
Output is correct |
92 |
Correct |
38 ms |
248 KB |
Output is correct |
93 |
Correct |
37 ms |
248 KB |
Output is correct |
94 |
Correct |
39 ms |
376 KB |
Output is correct |
95 |
Correct |
33 ms |
248 KB |
Output is correct |
96 |
Correct |
34 ms |
248 KB |
Output is correct |
97 |
Correct |
31 ms |
376 KB |
Output is correct |