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>
//#include"grader.cpp"
#ifdef EVAL
#else
#include"grader.cpp"
#endif
using namespace std;
int a[5005],N,tree[20005],flag[20005];
int gt(int v,int l,int r,int ql,int qr){
int val=0;
for(int i=ql;i<=qr;i++)val=max(a[i],val);
return val;
}
void upd(int v,int l,int r,int ql,int qr,int val){
for(int i=ql;i<=qr;i++)a[i]=max(a[i],val);
}
int GetBestPosition(int n,int C,int R,int *K,int *s,int *e){
N=n;
vector<int>S,E,v;
for(int i=0;i<N;i++)v.push_back(i);
for(int i=0;i<C;i++){
S.push_back(v[s[i]]);
E.push_back(v[e[i]]);
vector<int>temp;
for(int j=0;j<v.size();j++)if(!(s[i]<j&&j<=e[i]))temp.push_back(v[j]);
v.clear();
v.insert(v.end(),temp.begin(),temp.end());
}
int mx=-1,cnt,id;
for(int pos=0;pos<N;pos++){
for(int i=0;i<pos;i++)a[i]=K[i];
a[pos]=R;
for(int i=pos+1;i<N;i++)a[i]=K[i-1];
cnt=0;
for(int i=0;i<C;i++){
int tmp=gt(1,0,N-1,S[i],E[i]);
cnt+=(R==tmp);
upd(1,0,N-1,S[i],E[i],tmp);
}
if(cnt>mx){
mx=cnt;
id=pos;
}
}
return id;
}
/*
5 3 3
1
0
2
4
1 3
0 1
0 1
*/
Compilation message (stderr)
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int j=0;j<v.size();j++)if(!(s[i]<j&&j<=e[i]))temp.push_back(v[j]);
| ~^~~~~~~~~
tournament.cpp:45:12: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | return id;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |