Submission #943217

#TimeUsernameProblemLanguageResultExecution timeMemory
943217MisterReaperHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
754 ms92372 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...