이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |