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 in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define gg exit(0);
#include "prize.h"
const int N=200010;
int asked[N];
vector<int> f[N];
vector<int> qry(int i){
if(asked[i]) return f[i];
asked[i]=1;
return f[i]=ask(i-1);
}
int small=-1;
int same(int i,int j){
auto x=qry(j);
return x[0]+x[1]==small;
}
int cnt(int i,int j){
if(i>j) swap(i,j);
auto x=qry(i), y=qry(j);
return y[0]-x[0]-(x[0]+x[1]>y[0]+y[1]);
}
int find_best(int n){
int l=1,tmp=-1;
int shu=1;
forinc(t,1,200){
//int j=t>1 ? rnd(1,n) : 1;
int j;
if(t==1) j=1; else{
int g=rng();
g*=shu;
j=g%n+1;
}
auto a=qry(j);
if(a[0]+a[1]==0) return j-1;
if(tmp<a[0]+a[1]) tmp=a[0]+a[1];
shu=a[0]+a[1];
}
forinc(j,1,500){
auto a=qry(j);
if(a[0]+a[1]==0) return j-1;
if(small<a[0]+a[1]) small=a[0]+a[1];
}
if(small>tmp) exit(-1);
small=tmp;
int i=l, sz=0;
vector<int> val;
vector<int> lf(555),rt(555);
forinc(i,0,500){
lf[i]=1;
rt[i]=n;
}
int cur=0;
while(i<n){
int le=max(i+1,lf[cur]),mi,ri=rt[cur]; cur++;
while(le<=ri){
mi=(le+ri)/2;
if(same(l,mi)){
forinc(j,cnt(l,mi),500) lf[j]=max(lf[j],mi);
forinc(j,cur,cnt(l,mi)-1) rt[j]=min(rt[j],mi);
}
if(same(l,mi) && cnt(l,mi)==sz) i=mi,le=mi+1; else ri=mi-1;
}
if(i==n) break;
auto a=qry(++i);
if(a[0]+a[1]==0) return i-1;
sz++;
}
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:94:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |