# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84634 | farukkastamonuda | Trading (IZhO13_trading) | C++14 | 477 ms | 45684 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>
#define fi first
#define se second
#define mp make_pair
#define lo long long
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 300005
#define ii pair<int,int>
#define mid (start+end)/2
using namespace std;
int n,m,l,r,x,tree[li*4],lazy[li*4];
void push(int node,int start,int end){
if(lazy[node]==0) return ;
tree[node]=max(tree[node],lazy[node]);
if(start!=end){
lazy[node*2]=max(lazy[node*2],lazy[node]-(end-mid));
lazy[node*2+1]=max(lazy[node*2+1],lazy[node]);
}
lazy[node]=0;
}
void update(int node,int start,int end,int l,int r,int val){
push(node,start,end);
if(start>end || start>r || end<l) return ;
if(start>=l && end<=r){
lazy[node]=max(lazy[node],val-(r-end));
push(node,start,end);
return ;
}
update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
tree[node]=max(tree[node*2],tree[node*2+1]);
}
int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l) return -inf;
push(node,start,end);
if(start>=l && end<=r) return tree[node];
return max(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r));
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d %d %d",&l,&r,&x);
update(1,1,n,l,r,x+r-l);
}
for(int i=1;i<=n;i++){
printf("%d ",query(1,1,n,i,i));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |