Submission #874432

#TimeUsernameProblemLanguageResultExecution timeMemory
87443212345678Trading (IZhO13_trading)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int nx=3e5+5; int n, m, l, r, x; struct segtree { int d[4*nx]; void update(int l, int r, int i, int ql, int qr, int x) { if (r<ql||qr<l) return; if (ql<=l&&r<=qr) return void(d[i]=max(d[i], x)); int md=(l+r)/2; update(l, md, 2*i, ql, qr, x); update(md+1, r, 2*i+1, ql, qr, md+1-l+x); } void show(int l, int r, int i) { if (l==r) return void(cout<<max(d[i], 0)<<' '); int md=(l+r)/2; d[2*i]=max(d[2*i], d[i]); show(l, md, 2*i); d[2*i+1]=max(d[2*i+1], d[i]+md); show(md+1, r, 2*i+1); } } s; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; for (int i=1; i<=n; i++) s.d[i]=INT_MIN; for (int i=0; i<m; i++) cin>>l>>r>>x, s.update(1, n, 1, l, r, x-l+1); s.show(1, n, 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...