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 <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
mt19937 rng(time(nullptr));
const int N=2e5+99;
int n,sum,mxc,ans=-1,fen[N];
vector<int> res;
void add(int x){
for(x++;x<N;x+=(x&-x)){
fen[x]++;
}
}
int get(int x){
int res=0;
for(x++;x;x-=(x&-x)){
res+=fen[x];
}
return res;
}
void solve(vector<int> vec,int cnt){
//cout<<"Cnt "<<cnt<<endl;
//dbgv(vec);
if(cnt==0) return ;
int mid;
while(vec.size()){
mid=int(vec.size())>>1;
res=ask(vec[mid]);
if(res[0]+res[1]==0){
//cout<<"ans -> "<<vec[mid]<<endl;
ans=vec[mid];
add(vec[mid]);
}
if(res[0]+res[1]<mxc){
cnt--;
add(vec[mid]);
vec.erase(vec.begin()+mid);
}
else{
break;
}
}
if(vec.size()==0) return ;
vector<int> lc,rc;
int cntl,cntr,res0=res[0];
f(i,0,mid) lc.pb(vec[i]);
f(i,mid+1,vec.size()) rc.pb(vec[i]);
cntl=res0-get(vec[mid]-1);
cntr=cnt-cntl;
solve(lc,cntl);
solve(rc,cntr);
}
int find_best(int _n){
n=_n;
srand(time(NULL));
uniform_int_distribution<int> rnd(0,n-1);
f(i,0,155){
int id=(1ll*rand()*rand()+rand())%n;
res=ask(id);
maxm(mxc,res[0]+res[1]);
}
vector<int> vec(n);
iota(all(vec),0);
solve(vec,mxc);
//eror(ans);
return ans;
}
Compilation message (stderr)
prize.cpp: In function 'void solve(std::vector<int>, int)':
prize.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
69 | f(i,mid+1,vec.size()) rc.pb(vec[i]);
| ~~~~~~~~~~~~~~~~~~
prize.cpp:69:2: note: in expansion of macro 'f'
69 | f(i,mid+1,vec.size()) rc.pb(vec[i]);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |