Submission #865702

#TimeUsernameProblemLanguageResultExecution timeMemory
865702jk410Jousting tournament (IOI12_tournament)C++17
49 / 100
1058 ms1996 KiB
using namespace std; int N; int Tree[1<<18]; int A[100000]; int init(int l,int r,int n){ if (l==r) return Tree[n]=1; int m=(l+r)>>1; return Tree[n]=init(l,m,n<<1)+init(m+1,r,n<<1|1); } void propagate(int l,int r,int n){ if (l<r&&!Tree[n]) Tree[n<<1]=Tree[n<<1|1]=0; } int query(int x,int l,int r,int n){ propagate(l,r,n); if (l==r){ if (x==1) return l; return l+1; } int m=(l+r)>>1; if (Tree[n<<1]<x) return query(x-Tree[n<<1],m+1,r,n<<1|1); return query(x,l,m,n<<1); } int update(int lx,int rx,int l,int r,int n){ propagate(l,r,n); if (r<lx||rx<l) return Tree[n]; if (lx<=l&&r<=rx) return Tree[n]=0; int m=(l+r)>>1; return Tree[n]=update(lx,rx,l,m,n<<1)+update(lx,rx,m+1,r,n<<1|1); } int GetBestPosition(int _N, int C, int R, int *K, int *S, int *E){ N=_N; init(0,N-1,1); for (int i=0; i<C; i++){ int l=query(S[i]+1,0,N-1,1); int r=query(E[i]+2,0,N-1,1)-1; S[i]=l; E[i]=r; update(l+1,r,0,N-1,1); } int mxCnt=-1,ans; for (int t=0; t<N; t++){ for (int i=0; i<t; i++) A[i]=K[i]; A[t]=R; for (int i=t+1; i<N; i++) A[i]=K[i-1]; int l=t,r=t; while (l&&A[l-1]<A[t]) l--; while (r+1<N&&A[r+1]<A[t]) r++; int cnt=0; for (int i=0; i<C; i++){ if (S[i]<=t&&t<=E[i]){ if (S[i]<l||r<E[i]) break; cnt++; } } if (mxCnt<cnt){ mxCnt=cnt; ans=t; } } return ans; }

Compilation message (stderr)

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:71:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |     return ans;
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...