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<algorithm>
using namespace std;
const int idx = 1<<17;
int T[1<<18];
void update(int a){a+=idx;while(a)T[a]--,a>>=1;}
int read1(int x)
{
if(x==-1)return -1;
int a=1;
while(a<idx){
if(T[2*a]<x)x-=T[2*a],a=2*a+1;
else a=2*a;
}
return a-idx;
}
int read2(int a,int b)
{
a+=idx,b+=idx;
int ret = 0;
while(a<=b){
ret=max(ret,T[a]);
ret=max(ret,T[b]);
a = (a+1)>>1, b = (b-1)>>1;
}
return ret;
}
int sum[100010],ans;
int d[100010];
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E){
int i;
for(i=0;i<N;i++)d[i]=i+1,T[i+idx]=1;
for(i=idx-1;i;i--)T[i]=T[i<<1] + T[i<<1|1];
for(i=0;i<C;i++){
int a = read1(S[i]+1);
int tmp = a;
for(int j=0;j<E[i]-S[i];j++){
tmp = d[tmp];
update(tmp);
}
d[a] = d[tmp];
E[i] = d[tmp]-1;
S[i] = a;
}
for(i=0;i<N-1;i++)T[i+idx]=K[i];
for(i=idx-1;i;i--)T[i]=max(T[i<<1],T[i<<1|1]);
for(i=0;i<C;i++){
int s = read2(S[i],E[i]-1);
if(s<R)sum[S[i]]++,sum[E[i]+1]--;
}
for(i=0;i<N;i++)sum[i]+=sum[i-1];
for(i=0;i<N;i++)if(sum[ans]<sum[i])ans=i;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |