#include <bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
const int N=1e6+1;
const int inf=1e18;
const int mod=1e9+7;
using namespace std;
int n;
struct edge{
int mn,mx,ps;
};
vector<int>v;
edge t[4*N];
void build(int n,int tl,int tr){
if(tl==tr){
t[n].mx=v[tl];
t[n].mn=v[tl];
t[n].ps=tl;
return;
}
int mid=(tl+tr)/2;
build(n*2,tl,mid);
build(n*2+1,mid+1,tr);
t[n].mn=min(t[n*2].mn,t[n*2+1].mn);
t[n].mx=max(t[n*2].mx,t[n*2+1].mx);
if(t[n].mx==t[n*2].mx){
t[n].ps=t[n*2].ps;
}else{
t[n].ps=t[n*2+1].ps;
}
}
pair<int,int> getmx(int n,int tl,int tr,int l,int r){
if(tr<l||r<tl){
return {-1,-1};
}
if(l<=tl&&tr<=r){
return {t[n].mx,t[n].ps};
}
int mid=(tl+tr)/2;
pair<int,int> p=getmx(n*2,tl,mid,l,r);
pair<int,int> o=getmx(n*2+1,mid+1,tr,l,r);
pair<int,int> ans;
ans.first=max(p.first,o.first);
if(ans.first==p.first){
ans.second=p.second;
}else{
ans.second=o.second;
}
return ans;
}
int getmn(int n,int tl,int tr,int l,int r){
if(tr<l||r<tl){
return inf;
}
if(l<=tl&&tr<=r){
return t[n].mn;
}
int mid=(tl+tr)/2;
return min(getmn(n*2,tl,mid,l,r),getmn(n*2+1,mid+1,tr,l,r));
}
signed main(){
boost;
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
build(1,1,n);
while(m--){
int l,r,k;
cin>>l>>r>>k;
int mn=getmn(1,1,n,l,r);
pair<int,int>mx=getmx(1,1,n,l,r);
if(mx.first+mn<=k){
cout<<"1\n";
continue;
}
int ok=0;
while(mx.second==r){
r--;
if(l>=r){
ok=1;
break;
}
mx=getmx(1,1,n,l,r);
}
if(mx.first+mn<=k||ok==1){
cout<<"1\n";
}else{
cout<<"0\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1073 ms |
59700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
7884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |