제출 #1035025

#제출 시각아이디문제언어결과실행 시간메모리
103502512345678마상시합 토너먼트 (IOI12_tournament)C++17
0 / 100
1043 ms14160 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); for (int i=1; i<=N; i++) { if (i!=1) swap(c[i], c[i-1]); dfs(rt); if (!c[rt]) res=max(res, lvl[i]-1); else { int tmp=i, cnt=0; while (!c[pa[tmp][0]]) cnt++, tmp=pa[tmp][0]; res=max(res, cnt); } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...