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 i64 = long long;
int lsb(int x) {
return x & -x;
}
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<int> a(n + 1);
a[0] = 1E9 + 5;
for(int i = 1; i <= n; i++) {
std::cin >> a[i];
}
std::vector<std::array<int, 3>> qs[n + 1];
for(int i = 0; i < q; i++) {
int l, r, k;
std::cin >> l >> r >> k;
qs[r].push_back({l, k, i});
}
std::vector<int> mx(n + 1);
auto Update = [&](int p, int b) -> void {
for(int i = p; i > 0; i -= lsb(i)) {
mx[i] = std::max(mx[i], b);
}
};
auto Query = [&](int p) -> int {
int res = 0;
for(int i = p; i <= n; i += lsb(i)) {
res = std::max(res, mx[i]);
}
return res;
};
std::vector<int> st{0}, ans(q);
for(int i = 1; i <= n; i++) {
while(a[st.back()] <= a[i]) {
st.pop_back();
}
Update(st.back(), a[st.back()] + a[i]);
for(auto [l, k, idx] : qs[i]) {
ans[idx] = Query(l) <= k;
}
st.emplace_back(i);
}
for(int i = 0; i < q; i++) {
std::cout << ans[i] << "\n";
}
return;
}
signed main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL); std::cout.tie(NULL);
int t = 1; //std::cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
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... |