이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |