Submission #154041

#TimeUsernameProblemLanguageResultExecution timeMemory
154041beso123Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
829 ms90000 KiB
#include<bits/stdc++.h> #define int long long #define y second #define x first #define pii 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]}; return; } int mid=(i+j)/2; build(v*2,i,mid); build(v*2+1,mid+1,j); 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}; if(i==l && j==r) 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]; } int h=ceil((double)log2(n)); n=1<<h; 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:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sortbooks.cpp: In function '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:43: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...