Submission #236561

#TimeUsernameProblemLanguageResultExecution timeMemory
236561kshitij_sodaniHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
298 ms20344 KiB
#include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second int n; int it[100001]; int aa,bb,cc; int tree3[400001]; int tree2[400001]; vector<int> tree[400001]; void build(int no,int l,int r){ if(l==r){ tree3[no]=it[l]; tree[no].pb(it[l]); tree2[no]=it[l]; } else{ int mid=(l+r)/2; build(no*2+1,l,mid); build(no*2+2,mid+1,r); tree3[no]=max(tree3[no*2+1],tree3[no*2+2]); if(tree2[no*2+2]==-1 or tree2[no*2+1]==-1){ tree2[no]=-1; } else{ if(tree2[no*2+2]<tree3[no*2+1]){ tree2[no]=-1; } else{ tree2[no]=tree2[no*2+1]; } } /*while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){ if(tree[no*2+1][ind]<tree[no*2+2][ind2]){ tree[no].pb(tree[no*2+1][ind]); ind+=1; } else{ tree[no].pb(tree[no*2+2][ind2]); ind2+=1; } }*/ /*while(ind<tree[no*2+1].size()){ tree[no].pb(tree[no*2+1][ind]); ind+=1; } while(ind2<tree[no*2+2].size()){ tree[no].pb(tree[no*2+2][ind2]); ind2+=1; }*/ // auto x=lower_bound(tree[no*2+2].begin(),tree[no*2+2].end(),tree3[no*2+1]); /* if(tree[no*2+2][0]<tree3[no*2+1]){ int low=0; int high=(int)(tree[no*2+2].size())-1; int mid; while(low<high-1){ mid=(low+high)/2; if(tree[no*2+2][mid]<tree3[no*2+1]){ low=mid; } else{ high=mid; } } int ind=low; if(tree[no*2+2][high]<tree3[no*2+1]){ ind=max(ind,high); } tree2[no]=tree3[no*2+1]+tree[no*2+2][ind]; } else{ tree2[no]=0; }*/ /*auto x=lower_bound(tree[no*2+2].begin(),tree[no*2+2].end(),tree3[no*2+1]); if(x!=tree[no*2+2].begin()){ x--; tree2[no]=tree3[no*2+1]+(*x); } else{ tree2[no]=0; }*/ // tree2[no]=max(tree2[no],tree2[no*2+1]); // tree2[no]=max(tree2[no],tree2[no*2+2]); } // cout<<l<<","<<r<<","<<tree2[no]<<","<<tree3[no]<<endl; } int ans=0; int ma=0; int ko=0; void query(int no,int l,int r,int aa,int bb){ if(r<aa or l>bb){ return; } if(aa<=l and r<=bb){ // ans=max(ans,tree2[no]); if(ko){ if(tree2[no]<ma or tree2[no]==-1){ ans=it[l]; } ma=max(ma,tree3[no]); return; } /* if(tree[no][0]<ma){ int low=0; int high=(int)(tree[no].size())-1; int mid; while(low<high-1){ mid=(low+high)/2; if(tree[no][mid]<ma){ low=mid; } else{ high=mid; } } int ind=low; if(tree[no][high]<ma){ ind=max(ind,high); } ans=max(ans,ma+tree[no][ind]); }*/ /*auto x=lower_bound(tree[no].begin(),tree[no].end(),ma); if(x!=tree[no].begin()){ x--; ans=max(ans,(*x)+ma); }*/ ma=max(tree3[no],ma); } else{ int mid=(l+r)/2; query(no*2+1,l,mid,aa,bb); query(no*2+2,mid+1,r,aa,bb); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int m; cin>>n>>m; for(int i=0;i<n;i++){ cin>>it[i]; } int mi=it[0]; for(int i=0;i<n;i++){ mi=min(mi,it[i]); } build(0,0,n-1); for(int i=0;i<m;i++){ cin>>aa>>bb>>cc; aa-=1; bb-=1; ans=0; ma=0; ko=0; if(cc<mi){ ko=1; } query(0,0,n-1,aa,bb); cout<<((ans<=cc)?1:0)<<endl; } 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...