#include <bits/stdc++.h>
//#define int long long
using ll = int64_t;
using namespace std;
constexpr int maxn = 1E6 + 1;
vector <bool> t(maxn * 4);
vector <int> A(maxn + 1);
void build(int v, int tl, int tr) {
if(tl == tr) {
t[v] = true;
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
t[v] = ( t[v * 2] && t[v * 2 + 1] && (A[ tm ] <= A[tm + 1]) );
}
int get(int v, int tl, int tr, int l, int r) {
if(tl > r || l > tr) return 2;
if(l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2;
int res = get(v * 2, tl, tm, l, r) + get(v * 2 + 1, tm + 1, tr, l, r);
if(res > 2) return 1;
if(res < 2) return 0;
return (A[tm] <= A[tm + 1]);
}
void orz() {
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; ++i) {
cin >> A[i];
}
build(1, 1, N);
for(int i = 1; i <= M; ++i) {
int l, r, k;
cin >> l >> r >> k;
cout << get(1, 1, N, l, r) << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
//freopen("promote.in", "r", stdin);
//freopen("promote.out", "w", stdout);
int T = 1;
//cin >> T;
while(T--) orz();
return 0;
}
| # | 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... |