제출 #307862

#제출 시각아이디문제언어결과실행 시간메모리
307862Hehehe마상시합 토너먼트 (IOI12_tournament)C++14
0 / 100
135 ms3524 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<int, int> #define sz(x) (int)((x).size()) //#define int long long const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 2e6; const ll mod = 1e9 + 7; const int N = 2e5 + 11; const ll INF64 = 2e9 + 1; const double eps = 1e-14; const double PI = acos(-1); //ifstream in(".in"); //ofstream out(".out"); int t[8*N]; int sum[4*N], ans, nxt[4*N]; void update(int v, int l, int r, int pos, int val){ if(l == r){ t[v] = val; return; } int mid = (l + r) >> 1; if(pos <= mid)update(2*v, l, mid, pos, val);else update(2*v + 1, mid + 1, r, pos, val); t[v] = t[2*v] + t[2*v + 1]; } void update2(int v, int l, int r, int pos, int val){ if(l == r){ t[v] = val; return; } int mid = (l + r) >> 1; if(pos <= mid)update2(2*v, l, mid, pos, val);else update2(2*v + 1, mid + 1, r, pos, val); t[v] = max(t[2*v], t[2*v + 1]); } int xth(int v, int l, int r, int x){ if(l == r){ return l; } int mid = (l + r) >> 1; if(t[2*v] >= x)return xth(2*v, l, mid, x); return xth(2*v + 1, mid + 1, r, x - t[2*v]); } int mx(int v, int l, int r, int tl, int tr){ if(tl <= l && r <= tr)return t[v]; if(l > tr || r < tl)return -INF64; int mid = (l + r) >> 1; return max(mx(2*v, l, mid, tl, tr), mx(2*v + 1, mid + 1, r, tl ,tr)); } int GetBestPosition(int n, int C, int R, int *K, int *S, int *E){ //n--; for(int i = 1; i <= n; i++){ nxt[i] = i + 1; update(1, 1, n, i, 1); } for(int i = 1; i <= C; i++){ int a = xth(1, 1, n, S[i - 1] + 1); int tmp = a; for(int j = 1; j <= E[i - 1] - S[i - 1]; j++){ tmp = nxt[tmp]; update(1, 1, n, tmp, 0); } nxt[a] = nxt[tmp]; //cout << a << ' ' << nxt[tmp] << '\n'; E[i - 1] = nxt[tmp] - 1; S[i - 1] = a; } for(int i = 1; i < n; i++){ update(1, 1, n, i, 0); } for(int i = 1; i <= n; i++){ update2(1, 1, n, i, K[i - 1]); } for(int i = 1; i <= C; i++){ int s = mx(1, 1, n, S[i - 1], E[i - 1] - 1); if(s < R)sum[S[i - 1]]++, sum[E[i - 1] + 1]--; } for(int i = 1; i <= n; i++) sum[i] += sum[i - 1]; for(int i = 1; i <= n; i++)if(sum[ans] < sum[i]) ans = i; //cout << "Here" << '\n'; for(int i = 1; i <= n; i++){ //cout << sum[i] << ' '; }//cout << '\n'; return ans - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...