Submission #41322

#TimeUsernameProblemLanguageResultExecution timeMemory
41322MatheusLealVTrading (IZhO13_trading)C++14
100 / 100
425 ms11728 KiB
#include <bits/stdc++.h> #define inf 2000000000 #define N 300005 #define l (2*nod) #define r (2*nod + 1) #define mid ((a + b)/2) using namespace std; int n, m, tree[4*N], lazy[4*N]; inline void prop(int nod, int a, int b) { if(lazy[nod] == -inf) return; tree[nod] = max(tree[nod], lazy[nod]); if(a != b) { lazy[l] = max(lazy[l], lazy[nod]); lazy[r] = max(lazy[r], lazy[nod]); } lazy[nod] = -inf; } void upd(int nod, int a, int b, int i, int j, int x) { prop(nod, a, b); if(j < a || i > b) return; if(i <= a && j >= b) { tree[nod] = max(tree[nod], x); if(a != b) { lazy[l] = max(lazy[l], x); lazy[r] = max(lazy[r], x); } return; } upd(l, a, mid, i, j, x), upd(r, mid + 1, b, i, j, x); tree[nod] = max(tree[l], tree[r]); } int query(int nod, int a, int b, int i, int j) { prop(nod, a, b); if(j < a || i > b) return -inf; if(i <= a && j >= b) return tree[nod]; return max(query(l, a, mid, i, j), query(r, mid + 1, b, i, j)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(int i = 0; i < 4*N; i++) lazy[i] = tree[i] = -inf; for(int i = 1, a, b, x; i <= m; i++) { cin>>a>>b>>x; upd(1, 1, n, a, b, x - a); } for(int i = 1; i <= n; i++) { int ans = query(1, 1, n, i, i) + i; cout<<max(0, ans)<<" \n"[i == n]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...