#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Sz(x) (int)x.size()
const int N = 1e6 + 5;
int n, m, a[N], pref[N];
void solve() {
cin >> n >> m;
int mx_val = 0;
set <int> st[1005];
for (int i = 1; i <= n; i++) {
cin >> a[i];
st[a[i]].insert(i);
mx_val = max(mx_val, a[i]);
}
if (n <= 5000 && m <= 5000) {
while (m--) {
int l, r, k;
cin >> l >> r >> k;
int ok = 1, mx = 0;
for (int i = l; i <= r; i++) {
if (mx > a[i] && (mx + a[i]) > k) {
ok = 0;
}
mx = max(mx, a[i]);
}
if (ok) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
else if (mx_val <= 1000) {
vector <int> suf(1005, n + 1);
while (m--) {
int l, r, k;
cin >> l >> r >> k;
if (k >= 2000) {
cout << 1 << '\n';
continue;
}
for (int x = 1; x <= 1000; x++) {
auto to = st[x].lower_bound(l);
if (to != st[x].end() && *to <= r) suf[x] = *to;
else suf[x] = n + 1;
}
for (int x = 999; x >= 1; x--) {
suf[x] = min(suf[x + 1], suf[x]);
}
int ok = 1;
for (int x = 1; x <= 1000; x++) {
int R = max(x + 1, k - x + 1);
if (R > 1000) continue;
auto to = st[x].upper_bound(r);
if (to == st[x].begin()) continue;
to = prev(to);
if (*to < l) continue;
if (*to > suf[R]) {
ok = 0;
break;
}
}
if (ok) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
else {
for (int i = 2; i <= n; i++) {
pref[i] = pref[i - 1];
if (a[i] < a[i - 1]) pref[i]++;
}
while (m--) {
int l, r, k;
cin >> l >> r >> k;
if ((pref[r] - pref[l]) == 0) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
for (int T = 1; T <= t; T++) {
solve();
cout << '\n';
}
}
| # | 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... |