Submission #994913

#TimeUsernameProblemLanguageResultExecution timeMemory
994913yeediotJousting tournament (IOI12_tournament)C++17
0 / 100
90 ms13056 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define F first #define S second #define pb push_back void setio(){ freopen("/Users/iantsai/cpp/input.txt","r",stdin); freopen("/Users/iantsai/cpp/output.txt","w",stdout); } const int mxn = (1<<17)+10; const int inf=2e9; int n, m, rk, l[mxn], r[mxn], nl[mxn], nr[mxn], a[mxn]; struct BIT{ int bit[mxn]; void init(){ for(int i=0;i<mxn;i++){ bit[i] = 0; } } void m(int p, int v){ for(;p<mxn;p+=p&-p){ bit[p] += v; } } int q(int p){ int res = 0; for(;p;p-=p&-p){ res += bit[p]; } return res; } int bs(int x){ int pos = 0; for(int i=16;i>=0;i--){ if((pos | (1 << i)) <= n and bit[pos|(1<<i)] < x){ pos |= 1 << i; x -= bit[pos]; } } return pos+1; } }bt; struct segtree{ struct data{ int l, r, cnt; }seg[4*mxn]; void build(int l,int r,int id){ seg[id]={inf,-inf,0}; if(l==r){ return ; } int mm=l+r>>1; build(l,mm,id*2); build(mm+1,r,id*2+1); } void m(int l,int r,int id,int p,pii v){ if(l==r){ seg[id].l = v.F; seg[id].r = v.S; seg[id].cnt = 1; if(v.F==inf) seg[id].cnt=0; return ; } int mm = l+r>>1; if(p<=mm){ m(l,mm,id*2,p,v); } else{ m(mm+1,r,id*2+1,p,v); } seg[id].l=min(seg[id*2].l,seg[id*2+1].l); seg[id].r=max(seg[id*2].r,seg[id*2+1].r); seg[id].cnt=seg[id*2].cnt+seg[id*2+1].cnt; } void m(int p,pii v,int dic){ m(0,dic,1,p,v); } data q(int l,int r,int id,int ql,int qr){ if(qr<l or r<ql){ return {inf,-inf,0}; } if(ql<=l and r<=qr){ return seg[id]; } int mm =l+r>>1; data p =q(l,mm,id*2,ql,qr); data p2=q(mm+1,r,id*2+1,ql,qr); return {min(p.l,p2.l),max(p.r,p2.r),p.cnt+p2.cnt}; } }tr; vector<pair<int,pii>>in[mxn], out[mxn]; int nxt[mxn]; int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { n = N, m = C, rk = R; bt.init(); for(int i=1;i<=m;i++){ l[i] = S[i-1]+1; r[i] = E[i-1]+1; } for(int i=1;i<n;i++){ bt.m(i, 1); a[i] = K[i-1]; } tr.build(0,m,1); for(int i=1;i<=m;i++){ for(int j=r[i];j>=l[i];j--){ int p = bt.bs(j); if(j<r[i]){ bt.m(p, -1); } else{ nr[i] = p; } if(j == l[i]){ nl[i] = p; } } in[nl[i]].pb({i,{nl[i],nr[i]}}); out[nr[i]].pb({i,{nl[i],nr[i]}}); } nxt[n] = n+1; for(int i=n-1;i>=1;i--){ if(a[i]>rk){ nxt[i] = i+1; } else{ nxt[i] = nxt[i+1]; } } tr.m(0,{inf,-inf},m); int prev = 0, mx = -1, pos = 0; for(int i=1;i<=n;i++){ for(auto [id, p]:in[i]){ tr.m(id,p,m); } int l=0,r=m; while(l<r){ int mm=l+r+1>>1; auto [ql,qr,cnt] = tr.q(0,m,1,0,mm); if(ql<=prev or qr>=nxt[i]){ r=mm-1; } else{ l=mm; } } int cnt = tr.q(0,m,1,0,l).cnt; //cout << l <<','<<cnt<<'\n'; if(cnt>mx){ mx=cnt; pos=i; } for(auto [id,p]:out[i]){ tr.m(id,{inf,-inf},m); } if(a[i]>rk)prev=i; } return pos-1; } /*int main() { setio(); int tmp; int N, C, R; int *K, *S, *E; tmp = scanf("%d %d %d", &N, &C, &R); assert(tmp == 3); K = (int*) malloc((N-1) * sizeof(int)); S = (int*) malloc(C * sizeof(int)); E = (int*) malloc(C * sizeof(int)); int i; for (i = 0; i < N-1; i++) { tmp = scanf("%d", &K[i]); assert(tmp == 1); } for (i = 0; i < C; i++) { tmp = scanf("%d %d", &S[i], &E[i]); } printf("%d\n", GetBestPosition(N, C, R, K, S, E)); return 0; }*/

Compilation message (stderr)

tournament.cpp: In member function 'void segtree::build(int, int, int)':
tournament.cpp:53:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |         int mm=l+r>>1;
      |                ~^~
tournament.cpp: In member function 'void segtree::m(int, int, int, int, std::pair<int, int>)':
tournament.cpp:65:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |         int mm = l+r>>1;
      |                  ~^~
tournament.cpp: In member function 'segtree::data segtree::q(int, int, int, int, int)':
tournament.cpp:86:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |         int mm =l+r>>1;
      |                 ~^~
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:139:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  139 |             int mm=l+r+1>>1;
      |                    ~~~^~
tournament.cpp: In function 'void setio()':
tournament.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("/Users/iantsai/cpp/input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tournament.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("/Users/iantsai/cpp/output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...