제출 #242566

#제출 시각아이디문제언어결과실행 시간메모리
242566lyc마상시합 토너먼트 (IOI12_tournament)C++14
100 / 100
79 ms11384 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for (int i=(a);i>=(b);--i) using ii=pair<int,int>; const int mxN = 1e5+5; const int lgN = 17; const int mxC = 1e5+5; int l[mxC], r[mxC]; struct Fenwick { int ft[mxN], n; void i(int _n) { memset(ft,0,sizeof ft); n = _n; }; void u(int i, int x) { ++i; for (; i <= n; i += i&-i) ft[i] += x; } int q(int i) { ++i; int r = 0; for (; i; i -= i&-i) r += ft[i]; return r; } int f(int x) { int v = 0, i = 0; RFOR(k,lgN-1,0){ int j = i+(1<<k); if (j <= n && v+ft[j] < x) i = j, v += ft[j]; } return i+1-1; } } ft, ft2; struct SparseTable { int T[mxN][lgN], *A; void i(int n, int* _A) { A = _A; FOR(i,0,n-1) T[i][0] = i; FOR(k,1,lgN-1){ FOR(i,0,n-(1<<k)){ int p = T[i][k-1], q = T[i+(1<<(k-1))][k-1]; T[i][k] = (A[p] > A[q] ? p : q); } } } int q(int l, int r) { if (l > r) return -1; int k = floor(log2(r-l+1)); int p = T[l][k], q = T[r-(1<<k)+1][k]; return max(A[p],A[q]); } } spt; int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { FOR(i,0,N-1) l[i] = r[i] = i; ft.i(N-1); ft2.i(N+1); FOR(i,0,N-2) ft.u(i,1); spt.i(N-1,K); FOR(i,0,C-1){ int x = ft.f(S[i]+1); int ll = l[x], rr; ft.u(x,-1); FOR(j,1,E[i]-S[i]-1){ x = ft.f(S[i]+1); ft.u(x,-1); } if (S[i] < E[i]) x = ft.f(S[i]+1); rr = r[x]; l[x] = ll; if (spt.q(ll,rr-1) < R) { ft2.u(ll,1); ft2.u(rr+1,-1); } } int v = -1, j = -1; FOR(i,0,N-1){ int x = ft2.q(i); if (x > v) v = x, j = i; } return j; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...