Submission #1127925

#TimeUsernameProblemLanguageResultExecution timeMemory
1127925Mikael639Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
1260 ms97636 KiB
#include <bits/stdc++.h> #define fi first #define se second #define For(i, a, b) for (int i = (a); i <= (b); ++i) #define ForD(i, a, b) for (int i = (a); i >= (b); --i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repD(i, n) for (int i = (n) - 1; i >= 0; --i) #define coutE(x) {cout << x << '\n'; return;} #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define bs binary_search #define ub upper_bound #define lb lower_bound #define endl '\n' #define db long double #define ll long long #define vi vector<int> #define vii vector<ii> using namespace std; const int N = 1e6 + 5; int n, q, a[N]; bool ans[N]; struct query{ int r, k, i; }; vector<query> quer[N]; #define Node pair<int, int> struct Segment_treeeeeeeeee{ Node st[4 * N]; int lazy[4 * N]; Node Merge(Node a, Node b){ return {max(a.fi, b.fi), max(a.se, b.se)}; } void apply(int id, int x){ st[id].se = st[id].fi + x; lazy[id] = x; } void down(int id){ if (!lazy[id]) return; apply(id << 1, lazy[id]); apply(id << 1 | 1, lazy[id]); lazy[id] = 0; } void build(int id, int l, int r){ if (l == r){ st[id] = {a[l], 0}; return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); st[id] = Merge(st[id << 1], st[id << 1 | 1]); } void update(int id, int l, int r, int u, int v, int w){ if (v < l || r < u) return; if (u <= l && r <= v){ apply(id, w); return; } down(id); int mid = (l + r) >> 1; update(id << 1, l, mid, u, v, w); update(id << 1 | 1, mid + 1, r, u, v, w); st[id] = Merge(st[id << 1], st[id << 1 | 1]); } Node get(int id, int l, int r, int u, int v){ if (v < l || r < u) return {0, 0}; if (u <= l && r <= v) return st[id]; down(id); int mid = (l + r) >> 1; return Merge(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v)); } } ST; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; For(i, 1, n) cin >> a[i]; ST.build(1, 1, n); For(i, 1, q){ int l, r, k; cin >> l >> r >> k; quer[l].pb({r, k, i}); } stack<int> st; ForD(i, n, 1){ while (!st.empty() && a[st.top()] < a[i]) st.pop(); int bound = st.empty() ? n : st.top() - 1; st.push(i); if (i + 1 <= bound) ST.update(1, 1, n, i + 1, bound, a[i]); for (auto [r, k, id]: quer[i]){ ans[id] = ST.get(1, 1, n, i, r).se <= k; } } For(i, 1, q) cout << ans[i] << endl; 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...