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 N = 1e6 + 5;
const int Q = N;
int n, q, a[N], bit[N];
vector<int> qs[N];
bitset<N> ans;
struct t {
int l, r, k;
} query[Q];
void upd(int i, int x) {
while (i > 0) {
bit[i] = max(bit[i], x);
i -= i & -i;
}
}
int qry(int i) {
int r = 0;
while (i <= n) {
r = max(r, bit[i]);
i += i & -i;
}
return r;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
a[0] = int(1e9) + 1;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 0; i < q; ++i) {
cin >> query[i].l >> query[i].r >> query[i].k;
qs[query[i].r].push_back(i);
}
vector<int> st{0};
for (int i = 1; i <= n; ++i) {
while (a[st.back()] <= a[i]) st.pop_back();
upd(st.back(), a[i] + a[st.back()]);
st.push_back(i);
for (int j : qs[i]) ans[j] = qry(query[j].l) <= query[j].k;
}
for (int i = 0; i < q; ++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... |