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 = 1e6 + 5;
int tree[4*maxn], n, q;
void U(int u, int tl, int tr, int p, int v) {
if(tl == tr) {
tree[u] = max(tree[u], v);
} else {
int tm = (tl + tr) / 2;
if(p <= tm) U(2*u, tl, tm, p, v);
else U(2*u+1, tm+1, tr, p, v);
tree[u] = max(tree[2*u], tree[2*u+1]);
}
}
int Q(int u, int tl, int tr, int l, int r) {
if(l > tr || tl > r) return 0;
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return max(Q(2*u, tl, tm, l, r), Q(2*u+1, tm+1, tr, l, r));
}
int main() {
cin >> n >> q;
vector<int> v(n+1), ans(q);
for(int i=1; i<=n; i++) cin >> v[i];
vector<array<int, 3> > qus[n+1];
for(int i=0; i<q; i++) {
int l, r, k; cin >> l >> r >> k;
qus[r].push_back({ l, k, i });
}
stack<int> st;
for(int i=1; i<=n; i++) {
while(!st.empty() && v[st.top()] <= v[i]) st.pop();
if(!st.empty()) U(1, 1, n, st.top(), v[st.top()] + v[i]);
for(auto &[l, k, id] : qus[i]) ans[id] = (Q(1, 1, n, l, i) <= k);
st.push(i);
}
for(int x : ans) cout << x << '\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... |