Submission #543497

#TimeUsernameProblemLanguageResultExecution timeMemory
543497fuad27Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1808 ms116556 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 10; #define ff first #define ss second ll fen[N]; ll arr[N]; void upd(int at, ll val) { while(at > 0) { fen[at] = max(fen[at], val); at-=at&(-at); } } ll get(int r) { ll mx = 0; while(r < N) { mx = max(mx, fen[r]); r+=r&(-r); } return mx; } int main () { int n, m; cin >> n >> m; for(int i = 0;i<N;i++)fen[i] = 0; for(int i = 1;i<=n;i++)cin >> arr[i]; vector<pair<pair<ll,ll>, ll>> que[n+1]; for(int i = 0;i<m;i++) { ll l, r, v; cin >> l >> r >> v; que[r].push_back(make_pair(make_pair(l, v), i)); } ll ans[m]; vector<int> stk; stk.push_back(0); for(int i = 1;i<=n;i++) { while(stk.size() and arr[stk.back()] <= arr[i])stk.pop_back(); if(stk.size())upd(stk.back(), arr[stk.back()]+arr[i]); stk.push_back(i); for(auto q:que[i]) { ans[q.ss] = get(q.ff.ff)<=q.ff.ss; } } for(int i = 0;i<m;i++)cout << ans[i] << "\n"; }
#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...