#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
const int N=1e6+5;
int t[N*4],r[N*4],l[N*4],a[N];
void build(int v,int tl,int tr){
if(tl==tr){
t[v]=1;r[v]=l[v]=a[tl];
}
else{
int tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
t[v]=0;
if(t[v*2] && t[v*2+1] && r[v*2]<=l[v*2+1]){
t[v]=1;r[v]=r[v*2+1];l[v]=l[v*2];
}
}
}
int ans=-1,R=-1;
void get(int v,int tl,int tr,int left,int right){
if(right<tl or tr<left)return;
if(left<=tl && tr<=right){
if(ans==-1){
ans=t[v];
R=r[v];
}
else if(ans && t[v] && R<=l[v]){
R=r[v];
}
else ans=0;
return;
}
int tm=(tl+tr)/2;
get(v*2,tl,tm,left,right);
get(v*2+1,tm+1,tr,left,right);
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(q--){
int l,r,x;
cin>>l>>r>>x;
ans=-1;R=-1;
get(1,1,n,l,r);
cout<<ans<<"\n";
}
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
7 1
2 8 9 8 10 3 1
1 7 12
2 8 9 8 10 1 3
2 8 9 8 1 3 10
2 8 9 1 3 8 10
2 8 1 3 8 9 10
2 1 3 8 8 9 10
1 2 3 8 8 9 10
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1400 ms |
89104 KB |
Output is correct |
2 |
Correct |
1442 ms |
94828 KB |
Output is correct |
3 |
Correct |
1415 ms |
94872 KB |
Output is correct |
4 |
Correct |
1402 ms |
95204 KB |
Output is correct |
5 |
Correct |
1573 ms |
97204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
14856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |