#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAXN = 2e5 + 5;
const int SIZE = 350;
int cnt[MAXN], num_q;
vi memo[MAXN];
vi query(int x) {
if (memo[x].size() > 0)
return memo[x];
num_q++;
vi ret = ask(x);
return memo[x] = ret;
}
int find_best(int n) {
memset(cnt, 0, sizeof cnt);
fill(memo, memo + n + 1, vi());
num_q = 0;
/*
int mx = -1;
for (int i = 0, j; i < n; i = j + 1) {
if (i == n - 1) return i;
j = i;
vi cur = query(i);
if (cur[0] + cur[1] == 0) return i;
if (cur[0] + cur[1] < mx) continue;
mx = max(mx, cur[0] + cur[1]);
int lo = i + 1, hi = n - 1;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
vi now = query(mid);
if (now[0] + now[1] == 0) return mid;
if (now == cur) {
lo = mid + 1;
j = mid;
} else {
hi = mid - 1;
}
}
}
*/
for (int i = 0; i < n; i++) {
if (i == n - 1) return i;
vi cur = query(i);
int type = cur[0] + cur[1];
if (type == 0) return i;
cnt[type]++;
if (query(i + 1) != cur)
continue;
int b;
for (b = i / SIZE; (b + 1) * SIZE < n; b++) {
vi now = query((b + 1) * SIZE);
if (!(now == cur || (/*now[0] == cnt[type] + cur[0] && */now[1] >= cur[1])))
break;
cnt[now[0] + now[1]] += b * SIZE + SIZE - 1 - max(i, b * SIZE - 1);
}
int lo = max(i + 1, b * SIZE), hi = min(n - 1, (b + 1) * SIZE);
if (i == (b + 1) * SIZE - 1) {
lo = (b + 1) * SIZE;
hi = min(n - 1, (b + 2) * SIZE);
}
while (lo < hi) {
int mid = (lo + hi) >> 1;
vi now = query(mid);
if (now == cur || (/*now[0] == cnt[type] + cur[0] && */now[1] >= cur[1])) {
cnt[now[0] + now[1]] += mid - lo + 1;
lo = mid + 1;
} else {
hi = mid;
}
}
i = hi - 1;
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:81:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
5752 KB |
Output is correct |
2 |
Correct |
16 ms |
5824 KB |
Output is correct |
3 |
Correct |
11 ms |
5824 KB |
Output is correct |
4 |
Correct |
15 ms |
5872 KB |
Output is correct |
5 |
Correct |
12 ms |
5872 KB |
Output is correct |
6 |
Correct |
9 ms |
5952 KB |
Output is correct |
7 |
Correct |
13 ms |
6024 KB |
Output is correct |
8 |
Correct |
12 ms |
6024 KB |
Output is correct |
9 |
Correct |
11 ms |
6024 KB |
Output is correct |
10 |
Correct |
11 ms |
6024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6048 KB |
Output is correct |
2 |
Correct |
14 ms |
6048 KB |
Output is correct |
3 |
Correct |
12 ms |
6048 KB |
Output is correct |
4 |
Correct |
16 ms |
6076 KB |
Output is correct |
5 |
Correct |
12 ms |
6076 KB |
Output is correct |
6 |
Correct |
8 ms |
6076 KB |
Output is correct |
7 |
Correct |
10 ms |
6076 KB |
Output is correct |
8 |
Correct |
10 ms |
6076 KB |
Output is correct |
9 |
Correct |
15 ms |
6076 KB |
Output is correct |
10 |
Correct |
18 ms |
6076 KB |
Output is correct |
11 |
Correct |
13 ms |
6076 KB |
Output is correct |
12 |
Correct |
9 ms |
6076 KB |
Output is correct |
13 |
Correct |
20 ms |
6076 KB |
Output is correct |
14 |
Correct |
9 ms |
6076 KB |
Output is correct |
15 |
Correct |
12 ms |
6076 KB |
Output is correct |
16 |
Correct |
42 ms |
6076 KB |
Output is correct |
17 |
Correct |
8 ms |
6076 KB |
Output is correct |
18 |
Partially correct |
58 ms |
6076 KB |
Partially correct - number of queries: 5092 |
19 |
Correct |
9 ms |
6076 KB |
Output is correct |
20 |
Correct |
20 ms |
6076 KB |
Output is correct |
21 |
Correct |
30 ms |
6076 KB |
Output is correct |
22 |
Correct |
14 ms |
6076 KB |
Output is correct |
23 |
Correct |
9 ms |
6076 KB |
Output is correct |
24 |
Correct |
8 ms |
6076 KB |
Output is correct |
25 |
Correct |
30 ms |
6076 KB |
Output is correct |
26 |
Incorrect |
22 ms |
6104 KB |
answer is not correct |
27 |
Halted |
0 ms |
0 KB |
- |