#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const ll sz = 3e5+5;
const int mod = 998244353;
const ll inf = 1000000000000000;
ll res[sz];
vl st(sz<<2);
bool inran(ll x, ll l, ll r){
return x <= r && x >= l;
}
void push(ll v, ll tl, ll tr){
if(tl == tr || (!st[v])){return ;}
ll tm = (tl + tr)>>1;
st[v*2] = max(st[v*2], st[v]);
st[v*2+1] = max(st[v*2+1], st[v] + tm - tl + 1);
st[v] = 0;
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll val){
if(tl > r || tr < l){return ;}
if(tl >= l && tr <= r){
ll nl = val + tl - l;
st[v] = max(st[v], nl);
if(st[v]){
//cout << tl << ' ' << tr << ' ' << st[v] << endl;
}
//push(v, tl, tr);
return ;
}
push(v, tl, tr);
ll tm = (tl + tr)>>1;
update(v*2, tl, tm, l, r, val);
update(v*2+1, tm+1, tr, l, r, val);
}
void trav(ll v, ll l, ll r){
if(l == r){
res[l] = st[v];
return ;
}
push(v, l, r);
ll m = (l + r)>>1;
trav(v*2, l, m);
trav(v*2+1, m+1, r);
}
void solve()
{
ll n, m, i, j;
cin>>n>>m;
vl l(m), r(m), x(m);
for(i=0;i<m;i++){
cin>>l[i]>>r[i]>>x[i];
update(1, 1, n, l[i], r[i], x[i]);
}
trav(1, 1, n);
for(i=1;i<=n;i++){
cout << res[i] << ' ';
}cout << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
4
6
5 4 3 2 1 0
3
2 1 0
8
2 3 6 7 0 1 4 5
1
0
*/
Compilation message
trading.cpp: In function 'void solve()':
trading.cpp:58:17: warning: unused variable 'j' [-Wunused-variable]
58 | ll n, m, i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9820 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
3 ms |
9816 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
85 ms |
19168 KB |
Output is correct |
8 |
Correct |
92 ms |
20136 KB |
Output is correct |
9 |
Correct |
94 ms |
20448 KB |
Output is correct |
10 |
Correct |
110 ms |
20868 KB |
Output is correct |
11 |
Correct |
106 ms |
21412 KB |
Output is correct |
12 |
Correct |
117 ms |
22352 KB |
Output is correct |
13 |
Correct |
135 ms |
22452 KB |
Output is correct |
14 |
Correct |
128 ms |
22528 KB |
Output is correct |
15 |
Correct |
158 ms |
23864 KB |
Output is correct |
16 |
Correct |
150 ms |
24400 KB |
Output is correct |
17 |
Correct |
134 ms |
24220 KB |
Output is correct |
18 |
Correct |
160 ms |
24988 KB |
Output is correct |
19 |
Correct |
148 ms |
24576 KB |
Output is correct |
20 |
Correct |
170 ms |
26944 KB |
Output is correct |