This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#include "prize.h"
mt19937 rng(172831923);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) {
return l + rng() % (r - l + 1);
}
const int N = 2e5 + 10;
vector<int> ans[N];
int worst;
int check(int i, int j) {
if (ans[j].empty()) ans[j] = ask(j);
if (ans[0][j] + ans[1][j] != worst) return 2;
int tmp = ans[0][j] + ans[1][j] + ans[0][i] + ans[1][i] - worst;
return tmp > 0;
}
int find_best(int n) {
vector<tuple<int, int, int> > block;
int T = max(1, n / 785);
for(int i = 0; i < n; i += T) {
ans[i] = ask(i);
worst = max(worst, ans[i][0] + ans[i][1]);
}
for(int i = 1; i < n; i++) if (i % T) {
if (ans[i].empty()) ans[i] = ask(i);
if (ans[i][0] + ans[i][1] != worst) continue;
int l = i, r = n;
for(int j = T; j < n; j++) if (j > i) {
if (check(i, j)) {
r = j;
break;
}
l = j;
}
int last = l;
while (l <= r) {
int mid = l + r >> 1;
int tmp = check(i, mid);
if (!tmp) {
last = mid;
l = mid + 1;
}
else r = mid - 1;
}
i = last;
}
for(int i = 0; i < n; i++) if (!ans[i].empty() && ans[i][0] + ans[i][1] == 0) {
return i;
}
return 0;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:43:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |