Submission #888167

#TimeUsernameProblemLanguageResultExecution timeMemory
888167alex_2008Trading (IZhO13_trading)C++14
100 / 100
274 ms11752 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <unordered_set> #include <cstdlib> #include <cstring> #include <string> #include <set> #include <map> #include <algorithm> #include <bitset> #include <queue> #include <unordered_map> #include <fstream> #include <random> typedef unsigned long long ull; typedef long long ll; using namespace std; const int N = 3e5 + 10; int tree[4 * N]; int ans[N]; void update(int v, int tl, int tr, int l, int r, int val) { if (tl > r || tr < l) return; if (tl >= l && tr <= r) { tree[v] = max(tree[v], val + tl - l); return; } int tm = (tl + tr) / 2; update(2 * v, tl, tm, l, r, val); update(2 * v + 1, tm + 1, tr, l, r, val); } vector <int> cur; void pushh(int v, int tl, int tr) { bool ch = false; if (tree[v]) { cur.push_back(tree[v] - tl); ch = true; } if (tl == tr) { if (cur.empty()) ans[tl] = 0; else ans[tl] = *max_element(cur.begin(), cur.end()) + tl; } else { int tm = (tl + tr) / 2; pushh(2 * v, tl, tm); pushh(2 * v + 1, tm + 1, tr); } if (ch) cur.pop_back(); } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r, x; cin >> l >> r >> x; update(1, 1, n, l, r, x); } pushh(1, 1, n); for (int i = 1; i <= n; i++) { cout << ans[i] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...