This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int bit[100005], bit2[100005], b[100005];
set<int> s;
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), s.insert(i);
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);
vector<int> v;
for (auto it=s.lower_bound(L+1); it!=s.end(); it++)
{
if (*it>=R)
break;
fix(*it+1, 0), v.push_back(*it);
}
for (int x:v)
s.erase(s.find(x));
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |