#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define s second
#define f first
#define int long long
#define all(v) v.begin(),v.end()
const long long inf = 2e9 + 7;
const int N = 1e6 + 10;
void solve(){
int n,m;
cin >> n >> m;
int a[n + 1];
stack <int> st;
vector <int> last(n + 1),pr(n + 1);
for(int i = 1; i <= n;i++){
cin >> a[i];
while(st.size() > 0 && a[st.top()] <= a[i]){
st.pop();
}
if(st.size() > 0) last[i] = 1;
st.push(i);
}
for(int i = 1; i <= n; i++) pr[i] = pr[i - 1] + last[i];
while(m--){
int l,r,k;
cin >> l >> r >> k;
if(pr[r] - pr[l] == 0){
cout << 1 << '\n';
}
else cout << 0 << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("promote.in", "r", stdin);
//freopen("promote.out", "w", stdout);
int t1 = 1;
while(t1--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |