Submission #1035052

#TimeUsernameProblemLanguageResultExecution timeMemory
103505212345678Jousting tournament (IOI12_tournament)C++17
49 / 100
1028 ms14168 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5, kx=18; int n, c[2*nx], rt, nd[nx], cur, pa[2*nx][kx], lvl[2*nx], in[2*nx], out[2*nx], t, res; vector<int> d[2*nx]; void dfspa(int u, int p) { lvl[u]=lvl[p]+1; pa[u][0]=p; for (int i=1; i<kx; i++) pa[u][i]=pa[pa[u][i-1]][i-1]; for (auto v:d[u]) dfspa(v, u); } void dfs(int u) { if (u<=n) return; c[u]=0; for (auto v:d[u]) dfs(v), c[u]=c[u]|c[v]; } struct segtree { int d[4*nx]; void update(int l, int r, int i, int idx, int vl) { if (idx<l||r<idx) return; if (l==r) return d[i]+=vl, void(); int md=(l+r)/2; update(l, md, 2*i, idx, vl); update(md+1, r, 2*i+1, idx, vl); d[i]=d[2*i]+d[2*i+1]; } int query(int l, int r, int i, int key) { if (l==r) return l; int md=(l+r)/2; if (d[2*i]>=key) return query(l, md, 2*i, key); else return query(md+1, r, 2*i+1, key-d[2*i]); } } s; int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { n=cur=N; for (int i=1; i<=N; i++) nd[i]=i, s.update(1, N, 1, i, 1); for (int i=0; i<C; i++) { cur++; for (int j=S[i]+1; j<=E[i]+1; j++) { int idx=s.query(1, N, 1, S[i]+1); d[cur].push_back(nd[idx]); if (j==E[i]+1) nd[idx]=cur; else s.update(1, N, 1, idx, -1); } } for (int i=2; i<=N; i++) c[i]=K[i-2]>R; rt=cur; dfspa(rt, rt); pair<int, int> mx={-1, -1}; for (int i=1; i<=N; i++) { if (i!=1) swap(c[i], c[i-1]); dfs(rt); if (!c[rt]) mx=max(mx, {lvl[i]-1, -i}); else { int tmp=i, cnt=0; while (!c[pa[tmp][0]]) cnt++, tmp=pa[tmp][0]; mx=max(mx, {cnt, -i}); } } return -mx.second-1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...