Submission #862601

#TimeUsernameProblemLanguageResultExecution timeMemory
862601IrateTrading (IZhO13_trading)C++14
100 / 100
197 ms17488 KiB
#include<bits/stdc++.h> using namespace std; struct SegmentTree{ vector<int>sTree; vector<int>lazy; SegmentTree(int n){ sTree.resize(4 * n); lazy.resize(4 * n); } void Propagate(int node, int l, int r){ if(!lazy[node])return; if(l == r)sTree[node] = max(sTree[node], lazy[node]); if(l != r){ lazy[node * 2] = max(lazy[node * 2], lazy[node]); lazy[node * 2 + 1] = max(lazy[node * 2 + 1], ((2 * lazy[node] + r - l) >> 1) + 1); } lazy[node] = 0; } void R_Update(int node, int l, int r, int ql, int qr, int x){ Propagate(node, l, r); if(ql <= l && r <= qr){ lazy[node] = x + l - ql; Propagate(node, l, r); return; } if(ql > r || l > qr)return; int mid = (l + r) >> 1; R_Update(node * 2, l, mid, ql, qr, x); R_Update(node * 2 + 1, mid + 1, r, ql, qr, x); } int Query(int node, int l, int r, int pos){ Propagate(node, l, r); if(l == r)return sTree[node]; int mid = (l + r) >> 1; if(pos <= mid)return Query(node * 2, l, mid, pos); return Query(node * 2 + 1, mid + 1, r, pos); } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; SegmentTree tree(n); while(m--){ int l, r, x; cin >> l >> r >> x; tree.R_Update(1, 1, n, l, r, x); } for(int i = 1;i <= n;++i){ cout << tree.Query(1, 1, n, i) << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...