Submission #315899

#TimeUsernameProblemLanguageResultExecution timeMemory
315899amunduzbaevJousting tournament (IOI12_tournament)C++14
100 / 100
115 ms18796 KiB
//#include "grader.cpp" #include <bits/stdc++.h> using namespace std; const int N=1e5+5; int n, c, last, k[N], s[N], e[N]; vector<pair<int,int>> ranges; vector<int> pref; vector<vector<int>> edges; struct seg_tree{ int n; vector<int> tree; void mtree(int l,int r,int x){ if(l==r) { tree[x]=1; return; } int m=(l+r)/2; mtree(l,m,x*2); mtree(m+1,r,x*2+1); tree[x]=tree[x*2] + tree[x*2+1]; } void build(int N){ n=N; tree.assign(n*4, 0); mtree(1,n,1); } int get1(int val,int lx,int rx,int x){ if(lx==rx) return lx; int m=(lx+rx)/2; if(val <= tree[x*2]) return get1(val,lx,m,x*2); else return get1(val-tree[x*2], m+1, rx, x*2+1); } int get(int val){ return get1(val,1,n,1); } void update1(int l,int r,int lx,int rx,int x){ if(lx>r||rx<l) return; if(lx>=l&&rx<=r){ tree[x]=0; return; } int mid=(lx+rx)/2; update1(l,r,lx,mid,x*2); update1(l,r,mid+1,rx,x*2+1); tree[x] = tree[x*2]+tree[x*2+1]; } void update(int l,int r){ update1(l,r,1,n,1); } void print(){ for(int i=0;i<n*2;i++) cout<<tree[i]<<" "; cout<<"\n"; } int fr(){ return tree[1]; } }; pair<int,int> dfs(int u,int p=-1){ pair<int,int> ans = make_pair(0,ranges[u].first); for(auto v:edges[u]){ if(v==p) continue; auto it=dfs(v,u); ans = (it.first>ans.first ? it:ans); } if(pref[ranges[u].second-1] - pref[ranges[u].first-1] == 0) ans.first++; return ans; } bool cmp(pair<int,int> a,pair<int,int> b){ if(a.first==b.first) return a.second > b.second; return a.first < b.first; } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { //cout<<"WORKS\n"; n=N, c=C, last=R; for(int i=0;i<n-1;i++) k[i+1]=K[i]; for(int i=0;i<c;i++) s[i]=S[i]+1, e[i]=E[i]+1; seg_tree tree; tree.build(n); for(int i=0;i<c;i++){ int l = tree.get(s[i]); int r = ((e[i]+1 > tree.fr()) ? n : tree.get(e[i]+1)-1 ); ranges.push_back({l,r}); tree.update(l+1,r); } sort(ranges.begin(), ranges.end(), cmp); pref.assign(n+1,0); edges.resize(n+1); int i; for(i = 1; i < n; i++){ pref[i] += pref[i-1]; if(k[i] > last) pref[i]++; } for(i = 1; i < ranges.size(); i++){ int j = i-1; while(!(ranges[j].first <= ranges[i].first && ranges[j].second >= ranges[i].second)) j--; edges[i].push_back(j); edges[j].push_back(i); } auto ans = dfs(0); return --ans.second; } /* 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:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(i = 1; i < ranges.size(); i++){
      |                ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...