This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
int n, m, a[maxn], f[maxn], ans[maxn];
vector<array<int, 3> > q[maxn];
void upd(int i, int x) {
for(;i; i -= i&-i) f[i] = max(f[i], x);
}
int get(int i) {
int r = 0;
for(;i <= n; i += i&-i) r = max(f[i], r);
return r;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
a[0] = 1<<30;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int l, r, k, i = 0; i < m; i++) {
cin >> l >> r >> k;
q[r].push_back({l, k, i});
}
vector<int> t {0};
for(int i = 1; i <= n; i++) {
while(a[t.back()] <= a[i]) t.pop_back();
if(t.back()) upd(t.back(), a[t.back()] + a[i]);
t.push_back(i);
for(auto [l, k, p] : q[i]) ans[p] = get(l) <= k;
}
for(int i = 0; i < m; i++) cout << ans[i] << '\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... |