Submission #853868

#TimeUsernameProblemLanguageResultExecution timeMemory
853868Trisanu_DasHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
680 ms93732 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 1 << 20; int n, m, a[maxn], f[maxn], ans[maxn]; vector<array<int, 3> > q[maxn]; void upd(int i, int x) { for(;i; i -= i&-i) f[i] = max(f[i], x); } int get(int i) { int r = 0; for(;i <= n; i += i&-i) r = max(f[i], r); return r; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; a[0] = 1<<30; for(int i = 1; i <= n; i++) cin >> a[i]; for(int l, r, k, i = 0; i < m; i++) { cin >> l >> r >> k; q[r].push_back({l, k, i}); } vector<int> t {0}; for(int i = 1; i <= n; i++) { while(a[t.back()] <= a[i]) t.pop_back(); if(t.back()) upd(t.back(), a[t.back()] + a[i]); t.push_back(i); for(auto [l, k, p] : q[i]) ans[p] = get(l) <= k; } 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...