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 "prize.h"
#include <bits/stdc++.h>
#define sc second
#define fr first
#define mk make_pair
#define pb push_back
using namespace std;
const int N = (1e6 + 5);
const int inf = (1e9 + 7);
vector <int> res[N];
int mx,cur;
int u[N];
vector <pair<int,int> > v;
int find_best(int n) {
for (int i = min(n - 1,500); i >= 0; i --) {
if (res[i].size() == 0)
res[i] = ask(i);
int s = res[i][0] + res[i][1];
if (!s) return i;
if (!u[s]) v.pb(mk(s,i)),u[s] = 1;
}
sort(v.rbegin(),v.rend());
cur = v[0].sc;
if (v.size() > 1)
cur = min(cur,v[1].sc);
while(1) {
if (res[cur].size() == 0)
res[cur] = ask(cur);
if (res[cur][0] + res[cur][1] == 0) return cur;
if (v.size() == 1) {
if (res[cur][0] + res[cur][1] != v[0].fr) {
cur ++;
continue;
}
}
else {
if (res[cur][0] + res[cur][1] != v[0].fr && res[cur][0] + res[cur][1] != v[1].fr) {
cur ++;
continue;
}
}
int lf = res[cur][0];
int rt = res[cur][1];
int l = cur,r = n - 1;
while (r - l > 1) {
int m = (r + l) >> 1;
if (res[m].size() == 0)
res[m] = ask(m);
if (res[m][0] + res[m][1] == 0) return m;
if (res[m][0] >= lf && res[m][1] <= rt) l = m;
else r = m;
}
if (res[r].size() == 0)
res[r] = ask(r);
if (res[r][0] + res[r][1] == 0) return r;
if (res[r][0] >= lf && res[r][1] <= rt) l = r;
cur = l + 1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |