Submission #673116

#TimeUsernameProblemLanguageResultExecution timeMemory
673116kirakaminski968Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
2216 ms96276 KiB
#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 evan { 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] << endl; 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...