# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672433 | Baytoro | Trading (IZhO13_trading) | C++17 | 491 ms | 24384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=1e9+7;
const int N=3e5+5;
int sz;
vector<int> lazy,st;
void innit(int x){
sz=1;
while(sz<x)
sz*=2;
lazy.assign(2*sz-1,-INF);
st.assign(2*sz-1,-INF);
}
void push(int x, int l, int r){
if(r-l==1) return;
st[2*x+1]=max(st[2*x+1],lazy[x]);
st[2*x+2]=max(st[2*x+2],lazy[x]);
lazy[2*x+1]=max(lazy[2*x+1],lazy[x]);
lazy[2*x+2]=max(lazy[2*x+2],lazy[x]);
lazy[x]=-INF;
}
void update(int l, int r, int v, int x, int lx, int rx){
if(l>=rx || r<=lx)
return;
if(lx>=l && rx<=r){
st[x]=max(st[x],v);
lazy[x]=max(lazy[x],v);
return;
}
push(x,lx,rx);
int md=(lx+rx)/2;
update(l,r,v,2*x+1,lx,md);
update(l,r,v,2*x+2,md,rx);
st[x]=max(st[2*x+1],st[2*x+2]);
}
void update(int l, int r, int v){
update(l,r,v,0,0,sz);
}
int get(int i, int x, int lx, int rx){
if(rx-lx==1)
return st[x];
int md=(lx+rx)/2;
push(x,lx,rx);
if(i<md)
return get(i,2*x+1,lx,md);
else
return get(i,2*x+2,md,rx);
}
int get(int i){
return get(i,0,0,sz);
}
int n,m;
void solve(){
cin>>n>>m;
innit(n+1);
while(m--){
int l,r,v;cin>>l>>r>>v;
update(l,r+1,v-l,0,0,sz);
}
for(int i=1;i<=n;i++)
cout<<max(0ll,get(i)+i)<<' ';
}
main(){
//ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |