#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 5;
const int block = 500;
int n, m, a[N];
int mn[N / block + 5], mx[N / block + 5], ans[N / block + 5];
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
int blocks = (n + block - 1) / block;
for (int i = 0; i < blocks; i++) {
int l = i * block + 1;
int r = min(n, (i + 1) * block);
int Mn = LLONG_MAX, Mx = LLONG_MIN;
for (int j = l; j <= r; j++) {
Mn = min(Mn, a[j]);
Mx = max(Mx, a[j]);
}
mn[i] = Mn;
mx[i] = Mx;
int sum = LLONG_MIN;
bool found = false;
Mx = LLONG_MIN;
for (int j = l; j <= r; j++) {
if (Mx > a[j]) {
sum = max(sum, Mx + a[j]);
found = true;
}
Mx = max(Mx, a[j]);
}
ans[i] = found ? sum : LLONG_MIN;
}
while (m--) {
int l, r, k;
cin >> l >> r >> k;
int bl = (l - 1) / block, br = (r - 1) / block;
bool ok = true;
int Mx = LLONG_MIN;
if (bl == br) {
for (int i = l; i <= r; i++) {
if (Mx > a[i] && a[i] + Mx > k) ok = false;
Mx = max(Mx, a[i]);
}
} else {
for (int i = l; i <= (bl + 1) * block; i++) {
if (Mx > a[i] && a[i] + Mx > k) ok = false;
Mx = max(Mx, a[i]);
}
for (int i = bl + 1; i <= br - 1; i++) {
if (Mx > mn[i] && Mx + mn[i] > k) ok = false;
if (ans[i] != LLONG_MIN && ans[i] > k) ok = false;
Mx = max(Mx, mx[i]);
}
for (int i = br * block + 1; i <= r; i++) {
if (Mx > a[i] && a[i] + Mx > k) ok = false;
Mx = max(Mx, a[i]);
}
}
cout << (ok ? 1 : 0) << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
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... |