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 <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int lft[200100];
int rgt[200100];
int _ask(int x) {
if (lft[x]!=-1) return lft[x]+rgt[x];
auto res = ask(x);
lft[x]=res[0];
rgt[x]=res[1];
return lft[x]+rgt[x];
}
int mx=-1;
int ans=-1;
bool solve(int l,int r,int sl,int sr) {
int m=(l+r)>>1;
int res;
while (m<=r) {
res=_ask(m);
if (res==0) {
ans=m;
return false;
}
if (res>mx) {
mx=res;
return false;
}
if (res==mx) break;
m++;
}
if (m>r) {
//not found
m=(l+r)>>1;
m--;
while (m>=l) {
res=_ask(m);
if (res==0) {
ans=m;
return false;
}
if (res>mx) {
mx=res;
return false;
}
if (res==mx) break;
m--;
}
if (m<l) {
//not found
return true;
}
}
//normal
int ll=lft[m]-sl;
int rr=rgt[m]-sr;
if (ll) if (!solve(l,m-1,sl,rgt[m])) return false;
if (rr) if (!solve(m+1,r,lft[m],sr)) return false;
return true;
}
int find_best(int n) {
memset(lft,-1,sizeof(lft));
memset(rgt,-1,sizeof(rgt));
while (ans==-1) {
solve(0,n-1,0,0);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |