제출 #248814

#제출 시각아이디문제언어결과실행 시간메모리
248814alexandra_udristoiu마상시합 토너먼트 (IOI12_tournament)C++14
100 / 100
59 ms4728 KiB
#include<iostream> #define DIM 100005 using namespace std; static int aib[DIM], nxt[DIM], sum[DIM], pmax[DIM]; static int N; void update(int x, int val){ x++; for(; x <= N; x += (x & -x) ){ aib[x] += val; } } int query(int val){ int p, x = 0, sum = 0; for(p = 17; p >= 0; p--){ if( x + (1 << p) <= N && sum + aib[ x + (1 << p) ] < val){ sum += aib[ x + (1 << p) ]; x += (1 << p); } } return x; } int GetBestPosition(int n, int q, int r, int *v, int *s, int *e) { int i, j, p, u; N = n; for(i = 0; i < n; i++){ nxt[i] = i + 1; update(i, 1); } pmax[n + 1] = n + 1; for(i = n; i >= 1; i--){ pmax[i] = pmax[i + 1]; if(v[i] > r){ pmax[i] = i; } } for(i = 0; i < q; i++){ p = u = query(s[i] + 1); for(j = 1; j <= e[i] - s[i] + 1; j++){ u = nxt[u]; } int aux; for(j = nxt[p]; j != u; j = aux){ aux = nxt[j]; nxt[j] = u; update(j, -1); } nxt[p] = u; if(pmax[p] >= u - 1){ sum[p]++; sum[u - 1]--; } } p = 0; for(i = 1; i < n; i++){ sum[i] += sum[i - 1]; if(sum[p] < sum[i]){ p = i; } } return p; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...