Submission #931816

#TimeUsernameProblemLanguageResultExecution timeMemory
931816AiperiiiHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
13 / 100
1573 ms97204 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; const int N=1e6+5; int t[N*4],r[N*4],l[N*4],a[N]; void build(int v,int tl,int tr){ if(tl==tr){ t[v]=1;r[v]=l[v]=a[tl]; } else{ int tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); t[v]=0; if(t[v*2] && t[v*2+1] && r[v*2]<=l[v*2+1]){ t[v]=1;r[v]=r[v*2+1];l[v]=l[v*2]; } } } int ans=-1,R=-1; void get(int v,int tl,int tr,int left,int right){ if(right<tl or tr<left)return; if(left<=tl && tr<=right){ if(ans==-1){ ans=t[v]; R=r[v]; } else if(ans && t[v] && R<=l[v]){ R=r[v]; } else ans=0; return; } int tm=(tl+tr)/2; get(v*2,tl,tm,left,right); get(v*2+1,tm+1,tr,left,right); } signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,q; cin>>n>>q; for(int i=1;i<=n;i++)cin>>a[i]; build(1,1,n); while(q--){ int l,r,x; cin>>l>>r>>x; ans=-1;R=-1; get(1,1,n,l,r); cout<<ans<<"\n"; } } /* 5 2 3 5 1 8 2 1 3 6 2 5 3 7 1 2 8 9 8 10 3 1 1 7 12 2 8 9 8 10 1 3 2 8 9 8 1 3 10 2 8 9 1 3 8 10 2 8 1 3 8 9 10 2 1 3 8 8 9 10 1 2 3 8 8 9 10 */
#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...