Submission #600534

#TimeUsernameProblemLanguageResultExecution timeMemory
600534penguinhackerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1256 ms93680 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e6; int n, m, w[mxN], st[1<<21]; vector<ar<int, 3>> queries[mxN]; bool ans[mxN]; void upd(int i, int x, int u=1, int l=0, int r=n-1) { if (l==r) { st[u]=x; return; } int mid=(l+r)/2; i<=mid?upd(i, x, 2*u, l, mid):upd(i, x, 2*u+1, mid+1, r); st[u]=max(st[2*u], st[2*u+1]); } int qry(int ql, int qr, int u=1, int l=0, int r=n-1) { if (l>qr||r<ql) return 0; if (ql<=l&&r<=qr) return st[u]; int mid=(l+r)/2; return max(qry(ql, qr, 2*u, l, mid), qry(ql, qr, 2*u+1, mid+1, r)); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i=0; i<n; ++i) cin >> w[i]; for (int i=0; i<m; ++i) { int l, r, k; cin >> l >> r >> k, --l, --r; queries[r].push_back({l, k, i}); } vector<int> st; for (int i=0; i<n; ++i) { while(st.size()&&w[i]>=w[st.back()]) st.pop_back(); if (st.size()) upd(st.back(), w[i]+w[st.back()]); for (auto [l, k, ind] : queries[i]) ans[ind]=qry(l, i)<=k; st.push_back(i); } for (int i=0; i<m; ++i) cout << ans[i] << "\n"; 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...