Submission #583428

#TimeUsernameProblemLanguageResultExecution timeMemory
583428M_WJousting tournament (IOI12_tournament)C++17
100 / 100
703 ms15144 KiB
#include <bits/stdc++.h> #define ii pair<int, int> using namespace std; int a[100001], t[400004], lazy[400004], k[100001]; int t2[400004]; void build(int v, int tl, int tr){ if(tl == tr){ t[v] = 1; t2[v] = k[tl]; return; } int tm = (tl + tr) >> 1; build(v * 2, tl, tm); build(v * 2 + 1, tm + 1, tr); t[v] = t[v * 2] + t[v * 2 + 1]; t2[v] = max(t2[v * 2], t2[v * 2 + 1]); } void push(int v){ if(lazy[v] != 1) return; t[v * 2] = 0; lazy[v * 2] = lazy[v]; t[v * 2 + 1] = 0; lazy[v * 2 + 1] = lazy[v]; lazy[v] = 0; } void ins(int v, int tl, int tr, int l, int r, int val){ if(l > r) return; if(tl == l && tr == r){ t[v] = 0; lazy[v] = 1; return; } push(v); int tm = (tl + tr) >> 1; ins(v * 2, tl, tm, l, min(r, tm), val); ins(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val); t[v] = t[v * 2] + t[v * 2 + 1]; return; } int query(int v, int tl, int tr, int l, int r){ if(l > r) return 0; if(tl == l && tr == r) return t[v]; push(v); int tm = (tl + tr) >> 1; return query(v * 2, tl, tm, l, min(r, tm)) + query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r); } int query_max(int v, int tl, int tr, int l, int r){ if(l > r) return INT_MIN; if(tl == l && tr == r) return t2[v]; int tm = (tl + tr) >> 1; return max(query_max(v * 2, tl, tm, l, min(r, tm)), query_max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)); } vector<ii> v1[100001]; vector<int> v2[100001]; int val[100001], fwt[100001]; int nS[100001], nE[100001]; int query_f(int v){ int ret = 0; v++; for(; v > 0; v -= (v & -v)) ret += fwt[v]; return ret; } void ins_f(int v, int a){ v++; for(; v <= 100000; v += (v & -v)){ fwt[v] += a; } } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { for(int i = 0; i < N; i++) k[i] = K[i]; build(1, 0, N - 1); for(int i = 0; i < C; i++){ int l = 0, r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, 0, mid); if(q >= S[i] + 1) r = mid; else l = mid + 1; } int head = l, diff = E[i] - S[i] + 1; r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, head, mid); if(q >= diff) r = mid; else l = mid + 1; } int tail = l; l = 0; r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, 0, mid); if(q >= S[i]) r = mid; else l = mid + 1; } head = S[i] == 0 ? 0 : l + 1; v1[head].push_back({tail, i}); v2[tail + 1].push_back(i); ins(1, 0, N - 1, head, tail - 1, 0); val[i] = query_max(1, 0, N - 1, head, tail - 1); nS[i] = head; nE[i] = tail; } int ans = 0, pos = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; for(int i = 0; i < N; i++){ while(!pq.empty() && pq.top().second < i){ pq.pop(); } for(auto x : v2[i]) ins_f(x, -1); for(auto x : v1[i]){ if(val[x.second] > R) pq.push({x.second, x.first}); ins_f(x.second, 1); } int new_ans; if(!pq.empty()) new_ans = max(ans, query_f(pq.top().first) - 1); else new_ans = max(ans, query_f(100000)); if(new_ans > ans){ ans = new_ans; pos = i; } } return pos; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...