#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
trading.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main(){
| ^~~~
trading.cpp: In function 'void fopn(std::string)':
trading.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trading.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
5 ms |
464 KB |
Output is correct |
7 |
Correct |
245 ms |
12164 KB |
Output is correct |
8 |
Correct |
264 ms |
12716 KB |
Output is correct |
9 |
Correct |
273 ms |
12856 KB |
Output is correct |
10 |
Correct |
273 ms |
12868 KB |
Output is correct |
11 |
Correct |
288 ms |
13736 KB |
Output is correct |
12 |
Correct |
320 ms |
13740 KB |
Output is correct |
13 |
Correct |
330 ms |
14004 KB |
Output is correct |
14 |
Correct |
344 ms |
13828 KB |
Output is correct |
15 |
Correct |
381 ms |
14644 KB |
Output is correct |
16 |
Correct |
402 ms |
14640 KB |
Output is correct |
17 |
Correct |
401 ms |
22976 KB |
Output is correct |
18 |
Correct |
426 ms |
23472 KB |
Output is correct |
19 |
Correct |
408 ms |
23120 KB |
Output is correct |
20 |
Correct |
491 ms |
24384 KB |
Output is correct |