Submission #151705

#TimeUsernameProblemLanguageResultExecution timeMemory
151705leathermanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
64 / 100
3014 ms129488 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define m_p make_pair

using namespace std;
const int N = 4e6 + 200;

pair<int, int> v[N],b[N];
vector<int> q[N];
int t[4 * N],a[N],n,Q,limit,l,r,x,step,pos,val;
bool ans[N];
void upd(int v,int tl,int tr)
{
    if(tl == tr)
    {
        t[v] = val + a[tl];
        return;
    }
    int tm = (tl + tr) >> 1;
    if(pos <= tm) upd(v << 1, tl, tm);
    else upd(v << 1 | 1, tm + 1, tr);
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int get(int v,int tl,int tr)
{
    if(tr < l || tl > r) return 0;
    if(tl >= l && tr <= r) return t[v];
    int tm = (tl + tr) >> 1;
    return max(get(v << 1, tl, tm), get(v << 1 | 1, tm + 1, tr));
}
void make(int l,int r)
{
    int x,Pos;
    for(int i = r; i >= l; i--)
    {
        x = a[i];
        while(step > 0 && x > v[step].fi)
        {
            Pos = v[step].se;
            pos = Pos;
            val = x;
            upd(1, 1, n);
            step--;
        }
        v[++step] = {x, i};
    }
}
int main()
{
    ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
    cin>>n>>Q;
    for(int i = 1; i <= n; i++) cin>>a[i];
    limit = n;
    for(int i = 1; i <= Q; i++)
    {
        cin>>l>>r>>x;
        b[i] = {r, x};
        q[l].push_back(i);
    }
    for(int j = n; j > 0; j--) if(!q[j].empty())
        for(auto i : q[j])
        {
            l = j;
            r = b[i].fi;
            if(limit >= l)
            {
                make(l, limit);
                limit = l - 1;
            }
            x = get(1, 1, n);
            ans[i] = (x <= b[i].se);
        }
    for(int i = 1; i <= Q; i++) cout<<ans[i]<<"\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...