# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27245 | TAMREF | Trading (IZhO13_trading) | C++11 | 519 ms | 11400 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;
const int mx=300005, ms=1048577;
struct Segtree{
int a[mx],seg[ms],lz[ms];
int i,v,l,r;
Segtree(){
memset(a,0,sizeof(a));
fill(seg,seg+ms,INT_MIN);
fill(lz,lz+ms,INT_MIN);
}
int rmq(int n, int s, int e){
if(lz[n]!=INT_MIN){
seg[n]=max(seg[n],lz[n]);
if(s!=e){
lz[n<<1]=max(lz[n<<1],lz[n]);
lz[n<<1|1]=max(lz[n<<1|1],lz[n]);
} lz[n]=INT_MIN;
}
if(i<s||i>e) return INT_MIN;
if(s==i&&i==e) return seg[n];
int m=(s+e)>>1;
return seg[n]=max(rmq(n<<1,s,m),rmq(n<<1|1,m+1,e));
}
void update(int n, int s, int e){
if(lz[n]!=INT_MIN){
seg[n]=max(seg[n],lz[n]);
if(s!=e){
lz[n<<1]=max(lz[n<<1],lz[n]);
lz[n<<1|1]=max(lz[n<<1|1],lz[n]);
} lz[n]=INT_MIN;
}
if(s>r||e<l) return;
if(l<=s&&e<=r){
seg[n]=max(seg[n],v);
if(s!=e){
lz[n<<1]=max(lz[n<<1],v);
lz[n<<1|1]=max(lz[n<<1|1],v);
}
return;
}
int y=(s+e)>>1;
update(n<<1,s,y);
update(n<<1|1,y+1,e);
seg[n]=max(seg[n<<1],seg[n<<1|1]);
}
} S;
int main(){
int N,M;
for(scanf("%d%d",&N,&M);M--;){
scanf("%d%d%d",&S.l,&S.r,&S.v);
S.v-=S.l;
S.update(1,1,N);
}
for(S.i=1;S.i<=N;S.i++){
int t=S.rmq(1,1,N);
printf("%d ",(t==INT_MIN)?0:t+S.i);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |