# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245443 | LittleFlowers__ | The Big Prize (IOI17_prize) | C++17 | 0 ms | 0 KiB |
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());
mt19937 rng(1012);
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 same(int i,int j){
auto x=qry(i), y=qry(j);
return x[0]+x[1]==y[0]+y[1];
}
int cnt(int i,int j){
if(i>j) swap(i,j);
auto x=qry(i), y=qry(j);
return y[0]-x[0];
}
int find_best(int n){
int l,tmp=-1;
forinc(j,1,min(n,500)){
auto a=qry(j);
if(a[0]+a[1]==0) return j-1;
if(tmp<=a[0]+a[1]){
tmp=a[0]+a[1];
l=j;
}
}
int i=l, sz=0;
vector<int> val;
vector<int> lf(555),rt(555);
forinc(i,1,500){
lf[i]=1;
rt[i]=n;
}
int cur=0;
while(i<n){
int le=max(i+1,lf[cur]),mi,ri=pos[cur]; cur++;
while(le<=ri){
mi=(le+ri)/2;
if(same(l,mi)){
forinc(j,cur,cnt(l,mi)) 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++;
}
}