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;
#define pb push_back
#define ld long double
#define ll long long
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define lb lower_bound
#define ub upper_bound
// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 myrand(131);
std::vector<int> ask(int i);
const int N = 2e5 + 10;
pair<int, int> a[N];
int used[N];
int find_best(int n) {
memset(used, -1, sizeof(used));
int mxi = 0;
int mxQ = 450;
if(n >= 50000) {
mxQ = 100;
}
for(int i = 0; i < mxQ; i++) {
int cur = myrand() % n;
while (used[cur] == 1) {
cur = myrand() % n;
}
auto u = ask(cur);
a[cur].first = u[0];
a[cur].second = u[1];
if((u[0] + u[1]) == 0) {
return cur;
}
mxi = max(mxi, u[0] + u[1]);
used[cur] = 1;
}
for(int i = 0; i < n; i++) {
int ina = i, inb = n - 1, answ = i;
int lx, rx;
if(used[i] != -1) {
lx = a[i].first;
rx = a[i].second;
} else {
auto u = ask(i);
a[i].first = u[0];
a[i].second = u[1];
lx = u[0], rx = u[1];
used[i] = 1;
}
if((lx + rx) == 0) {
return i;
}
if((lx + rx) != mxi) {
continue;
}
while(ina <= inb) {
int mid = (ina + inb) / 2;
int l = 0, r = 0;
if(used[mid] != -1) {
l = a[mid].first;
r = a[mid].second;
} else {
auto u = ask(mid);
a[mid].first = u[0];
a[mid].second = u[1];
l = u[0], r = u[1];
used[i] = 1;
}
if((l + r) == 0) {
return mid;
}
if(l == lx && (l + r) == (lx + rx)) {
answ = mid;
ina = mid + 1;
} else {
inb = mid - 1;
}
}
i = answ;
}
// xd
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |