이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
//#include"grader.cpp"
using namespace std;
int a[5005],N,tree[20005],flag[20005];
void build(int v,int l,int r){
if(l==r){
tree[v]=a[l];
return;
}
int mid=(l+r)>>1;
build(v<<1,l,mid);
build((v<<1)+1,mid+1,r);
tree[v]=max(tree[v<<1],tree[(v<<1)+1]);
}
int gt(int v,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr)return tree[v];
if(r<ql||qr<l)return int(-2e9);
int mid=(l+r)>>1;
return max(gt(v<<1,l,mid,ql,qr),gt((v<<1)+1,mid+1,r,ql,qr));
}
void push(int v,int l,int r){
if(l!=r){
flag[v<<1]=max(flag[v<<1],flag[v]);
flag[(v<<1)+1]=max(flag[(v<<1)+1],flag[v]);
}
tree[v]=max(tree[v],flag[v]);
}
void upd(int v,int l,int r,int ql,int qr,int val){
if(ql<=l&&r<=qr){
flag[v]=max(flag[v],val);
return;
}
if(r<ql||qr<l)return;
push(v,l,r);
int mid=(l+r)>>1;
upd(v<<1,l,mid,ql,qr,val);
upd((v<<1)+1,mid+1,r,ql,qr,val);
tree[v]=max(tree[v<<1],tree[(v<<1)+1]);
}
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;
build(1,0,N-1);
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],mx);
}
if(cnt>mx){
mx=cnt;
id=pos;
}
}
return id;
}
/*
5 3 3
1
0
2
4
1 3
0 1
0 1
*/
컴파일 시 표준 에러 (stderr) 메시지
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j=0;j<v.size();j++)if(!(s[i]<j&&j<=e[i]))temp.push_back(v[j]);
| ~^~~~~~~~~
tournament.cpp:69:12: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
69 | 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... |