Submission #154090

#TimeUsernameProblemLanguageResultExecution timeMemory
154090beso123Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3066 ms67004 KiB
#include<bits/stdc++.h> #define int long long #define y second.first #define x first #define z second.second #define pii pair<int,pair<int,int>> using namespace std; int n,m,a[1000005]; pii t[4000005]; void build(int v,int i,int j){ if(i==j){ t[v]={a[i],{a[i],0}}; return; } int mid=(i+j)/2; build(v*2,i,mid); build(v*2+1,mid+1,j); if(t[v*2].y>t[v*2+1].x || t[v*2].y>t[v*2+1].y){ t[v].z=max(t[v].z,t[v*2].y); } t[v].x=min(t[v*2].x,t[v*2+1].x); t[v].y=max(t[v*2].y,t[v*2+1].y); } int ans=-1; pii get(int v,int i,int j,int l,int r){ if(l>r) return {-1,{-1,0}}; if(i==l && j==r){ ans=max(ans,t[v].z); return t[v]; } int mid=(i+j)/2; pii g1=get(v*2,i,mid,l,min(r,mid)); pii g2=get(v*2+1,mid+1,j,max(mid+1,l),r); if(g1.x!=-1 && g2.x!=-1){ if(g1.y>g2.x || g1.y>g2.y){ ans=max(g1.y,ans); } pii p; p.x=min(g1.x,g2.x); p.y=max(g1.y,g2.y); return p; } if(g1.x!=-1) return g1; if(g2.x!=-1) return g2; } main(){ cin>>n>>m; for(int k=1;k<=n;k++){ cin>>a[k]; } build(1,1,n); for(int k=1;k<=m;k++){ int l,r,s; cin>>l>>r>>s; ans=-1; pii g=get(1,1,n,l,r); if(ans==-1){ cout<<1<<endl; } else{ if(ans+g.x<=s) cout<<1<<endl; else cout<<0<<endl; } } return 0; }

Compilation message (stderr)

sortbooks.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sortbooks.cpp: In function 'std::pair<long long int, std::pair<long long int, long long int> > get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...