Submission #1111198

#TimeUsernameProblemLanguageResultExecution timeMemory
1111198borisAngelovHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
1652 ms174664 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int n, q; int a[maxn], prvBigger[maxn]; vector<int> points[maxn]; vector<tuple<int, int, int>> queries[maxn]; string answers[maxn]; struct Node { int maxv, lazy; }; struct SegmentTree { Node tree[4 * maxn]; void pushLazy(int node, int l, int r) { tree[node].maxv = max(tree[node].maxv, tree[node].lazy); if (l != r) { tree[2 * node].lazy = max(tree[2 * node].lazy, tree[node].lazy); tree[2 * node + 1].lazy = max(tree[2 * node + 1].lazy, tree[node].lazy); } tree[node].lazy = 0; } void update(int node, int l, int r, int ql, int qr, int value) { pushLazy(node, l, r); if (l > qr || r < ql) return; if (l == r) { tree[node].lazy = value; pushLazy(node, l, r); return; } int mid = (l + r) / 2; update(2 * node, l, mid, ql, qr, value); update(2 * node + 1, mid + 1, r, ql, qr, value); tree[node].maxv = max(tree[2 * node].maxv, tree[2 * node + 1].maxv); } int query(int node, int l, int r, int ql, int qr) { pushLazy(node, l, r); if (l > qr || r < ql) return 0; if (ql <= l && r <= qr) return tree[node].maxv; int mid = (l + r) / 2; return max(query(2 * node, l, mid, ql, qr), query(2 * node + 1, mid + 1, r, ql, qr)); } }; SegmentTree tree; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> q; for (int i = 1; i <= n; ++i) { cin >> a[i]; } stack<int> st; for (int i = 1; i <= n; ++i) { while (!st.empty() && a[st.top()] <= a[i]) st.pop(); if (!st.empty()) { prvBigger[i] = st.top(); points[st.top()].push_back(i); } st.push(i); } for (int i = 1; i <= q; ++i) { int l, r, k; cin >> l >> r >> k; queries[l].push_back({r, k, i}); } for (int i = n; i >= 1; --i) { for (auto x : points[i]) { tree.update(1, 1, n, i, x, a[i] + a[x]); //cout << "add " << i << " " << x << " :: " << a[i] + a[x] << endl; } for (auto [r, k, idx] : queries[i]) { //cout << i << " " << r << " :: " << tree.query(1, 1, n, i, r) << endl; if (tree.query(1, 1, n, i, r) <= k) answers[idx] = "1"; else answers[idx] = "0"; } } for (int i = 1; i <= q; ++i) cout << answers[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...