Submission #402053

#TimeUsernameProblemLanguageResultExecution timeMemory
402053JasiekstrzJousting tournament (IOI12_tournament)C++17
100 / 100
218 ms23632 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define fi first #define se second using namespace std; using namespace __gnu_pbds; const int NN=1e5; const int L=17; int d[NN+10]; tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> st; int mx[L+2][2][NN+10]; void build_rmq(int N,int *K) { for(int rot:{1,0}) { for(int i=0;i<N-1;i++) { mx[0][rot][i]=K[i]; for(int j=1;j<=L;j++) { if(i-(1<<(j-1))<0) mx[j][rot][i]=mx[j-1][rot][i]; else mx[j][rot][i]=max(mx[j-1][rot][i],mx[j-1][rot][i-(1<<(j-1))]); } } reverse(K,K+N-1); for(int j=0;j<=L;j++) { reverse(mx[j][0],mx[j][0]+N-1); reverse(mx[j][1],mx[j][1]+N-1); } } return; } int get_max(int l,int r) { int lg=__lg(r-l+1); return max(mx[lg][0][l],mx[lg][1][r]); } void add_interval(int l,int r,int R) { if(l==r || get_max(l,r-1)<R) { d[l]++; d[r+1]--; } return; } int GetBestPosition(int N,int C,int R,int *K,int *S,int *E) { build_rmq(N,K); for(int i=0;i<N;i++) st.insert(make_pair(i,i)); for(int i=0;i<C;i++) { auto s=(*st.find_by_order(S[i])),e=(*st.find_by_order(E[i])); add_interval(s.fi,e.se,R); st.erase(s); st.insert(make_pair(s.fi,e.se)); for(int j=E[i];j>S[i];j--) st.erase(st.find_by_order(j)); } int ans=0,bst=0; int curr=0; for(int i=0;i<N;i++) { curr+=d[i]; if(curr>ans) { ans=curr; bst=i; } } return bst; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...