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 <stdio.h>
#include <set>
#include <algorithm>
#define ff first
#define ss second
#define pii pair<int,int>
#define ele 131072
using namespace std;
int n,c,r;
int k[111111],s[111111],e[111111];
int ed[111111],res[111111];
int idx[333333],era[333333],sum[333333];
set<pii> st;
void putm_(int p,int num){
p+=ele; idx[p]=num;
for(p>>=1;p;p>>=1) idx[p]=max(idx[2*p],idx[2*p+1]);
}
void putq_(int p,int num){
for(p+=ele-1;p;p>>=1) sum[p]+=num;
}
int max_(int s,int e){
int mx=0;
s+=ele; e+=ele;
while(s<e){
if(s%2==1) mx=max(mx,idx[s++]);
if(e%2==0) mx=max(mx,idx[e--]);
s/=2; e/=2;
}
if(s==e) mx=max(mx,idx[s]);
return mx;
}
int get_real_pos(int n,int l,int r,int p){
int m=(l+r)/2;
if(l==r) return m;
if(p<=idx[2*n]) return get_real_pos(2*n,l,m,p);
return get_real_pos(2*n+1,m+1,r,p-idx[2*n]);
}
void erase_(int n,int l,int r,int s,int e){
if(r<s || l>e) return;
if(s<=l && r<=e){
era[n]=1;
sum[n]=0;
return;
}
int m=(l+r)/2;
erase_(2*n,l,m,s,e);
erase_(2*n+1,m+1,r,s,e);
if(era[n]) sum[n]=0;
else sum[n]=sum[2*n]+sum[2*n+1];
}
int GetBestPosition(int N,int C,int R,int *K,int *S,int *E){
n=N; c=C; r=R;
for(int i=0;i<N-1;i++) k[i]=K[i];
for(int i=0;i<C;i++) s[i]=S[i];
for(int i=0;i<C;i++) e[i]=E[i];
for(int i=0;i<n-1;i++) putm_(i,k[i]);
for(int i=0;i<n;i++) ed[i]=i;
for(int i=0;i<c;i++){
++s[i]; ++e[i];
int ss=get_real_pos(1,1,ele,s[i]);
int ee=get_real_pos(1,1,ele,e[i]); ee=ed[ee]-1;
s[i]=ss; e[i]=ee;
erase_(1,1,ele,ss+1,ee);
ed[ss]=ee;
}
for(int i=0;i<c;i++){
if(r>max_(s[i],e[i]-1)){
res[s[i]]++;
res[e[i]+1]--;
}
}
int mx=0,mxpos,tmp=0;
for(int i=0;i<n;i++){
tmp+=res[i];
if(mx<tmp){
mx=tmp;
mxpos=i;
}
}
return mxpos;
}
Compilation message (stderr)
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:96:12: warning: 'mxpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
return mxpos;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |