Submission #600528

#TimeUsernameProblemLanguageResultExecution timeMemory
600528penguinhackerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
1899 ms100820 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], lz[1<<21]; vector<ar<int, 3>> queries[mxN]; bool ans[mxN]; void psh(int u, int l, int r) { if (lz[u]) { st[u]+=lz[u]; if (l!=r) lz[2*u]+=lz[u], lz[2*u+1]+=lz[u]; lz[u]=0; } } void upd(int ql, int qr, int x, int u=1, int l=0, int r=n-1) { psh(u, l, r); if (l>qr||r<ql) return; if (ql<=l&&r<=qr) { lz[u]=x; psh(u, l, r); return; } int mid=(l+r)/2; upd(ql, qr, x, 2*u, l, mid); upd(ql, qr, 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) { psh(u, l, r); 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}); } stack<int> st; for (int i=0; i<n; ++i) { while(st.size()&&w[i]>=w[st.top()]) st.pop(); if (st.size()) upd(0, st.top(), w[i]+w[st.top()]-qry(st.top(), st.top())); for (auto [l, k, ind] : queries[i]) ans[ind]=qry(l, i)<=k; st.push(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...