Submission #949646

#TimeUsernameProblemLanguageResultExecution timeMemory
949646HanksburgerJousting tournament (IOI12_tournament)C++17
0 / 100
41 ms2140 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) { 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]--; // cout << L << "++ " << R << "--\n"; } fix(L+1, 1), fix(R+1, 1); for (int j=L+1; j<R; j++) fix(j+1, 0); /* for (int j=0; j<n; j++) cout << qry(j+1)-qry(j) << ' '; cout << '\n'; */ } int ans=b[0]; for (int i=1; i<n; i++) ans=max(ans, b[i]+=b[i-1]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...