Submission #949653

#TimeUsernameProblemLanguageResultExecution timeMemory
949653HanksburgerJousting tournament (IOI12_tournament)C++17
49 / 100
1033 ms2412 KiB
#include <bits/stdc++.h> using namespace std; int bit[100005], bit2[100005], b[100005]; void upd(int x, int y) { for (int i=x; i<=100000; i+=i&(-i)) bit[i]+=y; } void upd2(int x, int y) { for (int i=x; i<=100000; i+=i&(-i)) bit2[i]+=y; } int qry(int x) { int res=0; for (int i=x; i; i-=i&(-i)) res+=bit[i]; return res; } int qry2(int x) { int res=0; for (int i=x; i; i-=i&(-i)) res+=bit2[i]; return res; } void fix(int x, int y) { upd(x, y-(qry(x)-qry(x-1))); } int f(int x) { int l=0, r=99999; while (l<r) { int mid=(l+r)/2; if (qry(mid+1)<x) l=mid+1; else r=mid; } return l; } int GetBestPosition(int n, int m, int k, int *a, int *l, int *r) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i=0; i<n-1; i++) upd2(i+1, a[i]>k); for (int i=0; i<n; i++) upd(i+1, 2); for (int i=0; i<m; i++) { int L=f(l[i]*2+1), R=f(r[i]*2+2); if (qry2(L)==qry2(R)) b[L]++, b[R]--; fix(L+1, 1), fix(R+1, 1); for (int j=L+1; j<R; j++) fix(j+1, 0); } int ind=0, mx=b[0]; for (int i=1; i<n; i++) if (mx<(b[i]+=b[i-1])) mx=b[i], ind=i; return ind; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...