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<vector>
#include<iostream>
using namespace std;
typedef long long ll;
const int TREE_SIZE=1<<17;
int max_tree[2*TREE_SIZE];
void set_max_tree(int i,int v){
int node=TREE_SIZE+i;
max_tree[node]=v;
node/=2;
while(node){
max_tree[node]=max(max_tree[2*node],max_tree[2*node+1]);
node/=2;
}
}
int get_max(int node,int l,int r,int rl,int rr){
if(r<=rl||rr<=l)
return 0;
if(l<=rl&&rr<=r)
return max_tree[node];
int mid=(rl+rr)/2;
return max(get_max(2*node,l,r,rl,mid),get_max(2*node+1,l,r,mid,rr));
}
int get_max(int l,int r){
return get_max(1,l,r,0,TREE_SIZE);
}
int GetBestPosition(int n,int c,int r,int *K,int *L,int *R){
for(int i=0;i<c;i++)
R[i]++;
vector<int>present(n,1);
for(int j=0;j<c;j++){
int sum=0;
int l=n,r=n;
for(int i=0;i<n;i++){
if(sum==L[j]&&l==n)
l=i;
if(sum==R[j]&&r==n)
r=i;
sum+=present[i];
}
L[j]=l;
R[j]=r;
//cout<<l<<" "<<r<<"\n";
for(int i=l;i<r-1;i++)
present[i]=0;
}
for(int i=0;i<n-1;i++)
set_max_tree(i,K[i]);
int max_res=-1;
int i_res=0;
for(int ins=0;ins<n;ins++){
//(int i:arr)
//cout<<i<<" ";
//cout<<"\n";
int res=0;
for(int j=0;j<c;j++){
int left=L[j];
int right=R[j];
if(left>ins)
continue;
if(right<=ins)
continue;
right--;
int m=get_max(left,right);
if(m<r)
res++;
}
//cout<<ins<<" "<<res<<"\n";
if(res>max_res){
max_res=res;
i_res=ins;
}
}
return i_res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |