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>
#include "prize.h"
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
#define X first
#define Y second
#define PB push_back
#define PPB pop_back
#define all(x) (x).begin(), (x).end()
const int MAXN = 2e5 + 7;
mt19937 rng(time(0));
vi mog;
int svi;
ii q[MAXN];
void as(int x){
if(q[x].X == -1){
vi ret = ask(x);
q[x] = {ret[0], ret[1]};
}
}
int l(int x){
as(x);
return q[x].X;
}
int r(int x){
as(x);
return q[x].Y;
}
void rek(int lo, int hi){
if(lo > hi) return;
if(l(lo) + r(lo) < svi){
mog.PB(lo);
rek(lo + 1, hi);
return;
}
if(l(hi) + r(hi) < svi){
mog.PB(hi);
rek(lo, hi - 1);
return;
}
if(l(lo) == l(hi) or lo + 1 == hi) return;
int mid = (lo + hi) / 2;
rek(lo, mid);
rek(mid, hi);
}
int find_best(int n){
fill(q, q + n, (ii){-1, -1});
for(int i=0; i<100; i++){
int x = rng() % n;
svi = max(svi, l(x) + r(x));
}
rek(0, n-1);
for(auto &x : mog) if(l(x) + r(x) == 0) return x;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
69 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |