#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
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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
829 ms |
90000 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
7416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |