Submission #539360

#TimeUsernameProblemLanguageResultExecution timeMemory
539360PiejanVDCHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
64 / 100
1183 ms262144 KiB
#include <bits/stdc++.h> using namespace std; vector<int>w; vector<int>st; vector<vector<int>>v; void build(int i, int j, int p) { if(i == j) { st[p] = 0; v[p] = {w[i]}; return; } int mid = (i+j)/2; build(i, mid, 2*p), build(mid+1, j, 2*p+1); const int n = (int)v[2*p].size(), m = (int)v[2*p+1].size(); int pp = 0; st[p] = max(st[2*p], st[2*p+1]); for(int ii = 0 ; ii < n ; ii++) { while(pp < m && v[2*p+1][pp] < v[2*p][ii]) { st[p] = max(st[p], v[2*p].back() + v[2*p+1][pp]); v[p].push_back(v[2*p+1][pp]); pp++; } v[p].push_back(v[2*p][ii]); } while(pp < m) v[p].push_back(v[2*p+1][pp++]); //cout << i <<" " << j << " " << st[p] << "\n"; } int ans; int l,r; int query(int i, int j, int p, int mx) { if(i > r || j < l) return -1; if(i >= l && j <= r) { ans = max(ans, st[p]); if(1) { const int n = (int)v[p].size(); int le = 0, re = n-1, ret = -1; while(le <= re) { int mi = (le+re)/2; if(v[p][mi] < mx) { ret = mi; le = mi+1; } else re = mi-1; } ans = max(ans, (ret == -1 ? 0 : mx + v[p][ret])); } return v[p].back(); } int mid = (i+j)/2; mx = max(mx, query(i, mid, 2*p, mx)); mx = max(mx, query(mid+1, j, 2*p+1, mx)); return mx; } signed main() { int n,q; cin>>n>>q; w.resize(n); st.resize(8 * n); v.resize(8 * n); for(auto &z : w) cin>>z; build(0, n-1, 1); while(q--) { int k; cin>>l>>r>>k; l--,r--; ans = 0; query(0,n-1,1,-1); cout << (ans <= k) << "\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...