#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5, off = 1048576;
int n, q, a[maxn], l[maxn], r[maxn], k[maxn], in[maxn], prosli[maxn], ans[maxn], T[off * 2 + 5];
vector <int> v, d[maxn];
int comp (int x, int y){
if (l[x] > l[y]) return 1;
return 0;
}
int query (int x, int y, int pos, int low, int high){
if (low >= x and high <= y) return T[pos];
if (low > y or high < x) return 0;
int mid = (low + high) / 2;
return max(query(x, y, pos * 2, low, mid), query(x, y, pos * 2 + 1, mid + 1, high));
}
void update (int pos, int val){
pos += off;
T[pos] = val;
pos = pos / 2;
while (pos > 0){
T[pos] = max(T[pos * 2], T[pos * 2 + 1]);
pos = pos / 2;
}
}
void dodaj (int maxi, int mini){
for (int i = maxi; i >= mini; i--){
for (int j = 0; j < d[i].size(); j++) update(d[i][j], a[d[i][j]] + a[prosli[d[i][j]]]);
}
}
int main (void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> q;
for (int i = 0; i < n; i++){
cin >> a[i];
while (v.size() > 0 and a[v.back()] <= a[i]) v.pop_back();
if (v.size() > 0){
prosli[i] = v.back();
d[prosli[i]].push_back(i);
}
else prosli[i] = -1;
v.push_back(i);
}
for (int i = 0; i < q; i++){
cin >> l[i] >> r[i] >> k[i];
l[i]--, r[i]--;
in[i] = i;
}
sort(in, in + q, comp);
int bio = n - 1;
for (int j = 0; j < q; j++){
int i = in[j];
dodaj(bio, l[i]);
bio = l[i] - 1;
if (query(l[i], r[i], 1, 0, off - 1) > k[i]) ans[i] = 0;
else ans[i] = 1;
}
for (int i = 0; i < q; i++) cout << ans[i] << "\n";
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... |