Submission #684529

#TimeUsernameProblemLanguageResultExecution timeMemory
684529NintsiChkhaidzeTrading (IZhO13_trading)C++14
100 / 100
290 ms24344 KiB
#include <bits/stdc++.h> #define ll long long #define left (h<<1),l,((l+r)>>1) #define right ((h<<1)|1),((l+r)>>1) + 1,r #define pb push_back #define s second #define f first #define pii pair<int,int> #define int ll using namespace std; const int N = 300005,inf = -1e18; int t[4*N],lz[4*N]; void push(int h){ if (lz[h] == inf) return; lz[h*2]=max(lz[h*2],lz[h]); lz[h*2+1]=max(lz[h*2+1],lz[h]); t[h*2]=max(t[h*2],lz[h]); t[h*2+1]=max(t[h*2+1],lz[h]); lz[h] = inf; } void upd(int h,int l,int r,int L,int R,int x){ if (r < L || R < l) return; if (L <= l && r <= R){ t[h] = max(t[h],x); lz[h] = max(lz[h],x); return; } push(h); upd(left,L,R,x); upd(right,L,R,x); t[h] = max(t[h*2],t[h*2+1]); } int get(int h,int l,int r,int idx){ if (l == r) return t[h]; push(h); if (idx > (l + r)>>1) return get(right,idx); return get(left,idx); } void build(int h,int l,int r){ t[h] = lz[h] = inf; if (l==r) return; build(left);build(right); } signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,q; cin>>n>>q; build(1,1,n); while (q--){ int l,r,x; cin>>l>>r>>x; upd(1,1,n,l,r,x-l); } for (int i = 1; i <= n; i++){ int p = get(1,1,n,i); if (p == inf) cout<<0<<" "; else cout<<p + i<<" "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...