Submission #990750

#TimeUsernameProblemLanguageResultExecution timeMemory
990750perchutsHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
2315 ms65916 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int seg[4*maxn], w[maxn]; void upd(int i, int l, int r, int x, int k) { if (l == r) { seg[i] = max(seg[i], k + w[l]); return; } int md = (l + r) / 2; if (x <= md) upd(2*i, l, md, x, k); else upd(2*i+1, md+1, r, x, k); seg[i] = max(seg[2*i], seg[2*i+1]); } int query(int i, int l, int r, int x, int y) { if (r < x || y < l) return 0; if (x <= l && r <= y) return seg[i]; int md = (l + r) / 2; return max(query(2*i, l, md, x, y), query(2*i+1, md+1, r, x, y)); } int main() { int n, q, xx = 0; cin >> n >> q; for (int i = 1; i <= n; ++i) cin >> w[i]; using iii = tuple<int,int,int, int>; vector<iii> queries(q); for (auto& [r, l, k, id] : queries) cin >> l >> r >> k, id = xx++; sort(begin(queries), end(queries)); vector<int> ans(q); int pt = 1; stack<int> st; for (auto [r, l, k, id] : queries) { while (pt <= r) { while (!st.empty() && w[st.top()] <= w[pt]) st.pop(); if (!st.empty()) { upd(1, 1, n, st.top(), w[pt]); } st.push(pt++); } ans[id] = (query(1, 1, n, l, r) <= k); } for (int i = 0; i < q; ++i) cout << ans[i] << endl; }
#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...