Submission #1156477

#TimeUsernameProblemLanguageResultExecution timeMemory
1156477SyedSohaib_123Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
2722 ms237980 KiB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define append push_back
// #define int long long

const int N=1e6+10,LG=21;
int mod=998244353;

int a[N],tree[N<<2],n,most,mxx;
vector<int>seg[N<<2];

void build(int l=1,int r=n,int s=1){
    if(l==r){
        seg[s]={a[l]};
        return;
    }
    int m=(l+r)>>1;
    build(l,m,s*2);
    build(m+1,r,s*2+1);
    tree[s]=max(tree[s*2],tree[s*2+1]);
    if(seg[s*2].back()>seg[s*2+1][0]) tree[s]=max(seg[s*2].back()+*(--lower_bound(seg[s*2+1].begin(),seg[s*2+1].end(),seg[s*2].back())),tree[s]);
    int x,y;
    x=y=0;
    while(x<seg[s*2].size() and y<seg[s*2+1].size()){
        if(seg[s*2][x]<seg[s*2+1][y]){
            seg[s].append(seg[s*2][x]);
            x++;
        }
        else{
            seg[s].append(seg[s*2+1][y]);
            y++;
        }
    }
    while(x<seg[s*2].size()) seg[s].append(seg[s*2][x]),x++;
    while(y<seg[s*2+1].size()) seg[s].append(seg[s*2+1][y]),y++;
}
void get(int &a,int &b,int l=1,int r=n,int s=1){
    if(r<a or l>b) return;
    if(a<=l and r<=b){
        most=max(most,tree[s]);
        if(mxx>seg[s][0]) most=max(most,mxx+*(--lower_bound(seg[s].begin(),seg[s].end(),mxx)));
        mxx=max(mxx,seg[s].back());
        return;
    }
    int m=(l+r)>>1;
    get(a,b,l,m,s*2);
    get(a,b,m+1,r,s*2+1);
}

void solve(int tst){
    int m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    build();
    while(m--){
        int a,b_,c;
        cin>>a>>b_>>c;
        most=mxx=0;
        get(a,b_);
        cout<<(most<=c)<<endl;
    }
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    for(int i=1;i<=t;i++){
        solve(i);
        // if(i!=t) cout<<endl;
    }
}
#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...