#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 3e5 + 5;
tuple<int,int,int> v[N];
ll mx[N], bit[N];
const ll inf = 1e15;
void upd(int i, ll val){
for(; i<N; i+=i&-i) bit[i] = max(bit[i], val);
}
ll qry(int i){
ll res = -inf; for(; i; i-=i&-i) res = max(res, bit[i]); return res;
}
signed main(){
int n, m; scanf("%d %d", &n, &m);
for(int i = 0, l, r, x; i<m; ++i){
scanf("%d %d %d", &l, &r, &x);
v[i] = make_tuple(r, l, x);
}
sort(v, v+m);
fill(bit, bit+N, -inf);
for(int i = n, j = m-1; i>=1; --i){
while(j>=0 && get<0>(v[j]) >= i){
upd(get<1>(v[j]), get<2>(v[j]) - get<1>(v[j]));
--j;
}
mx[i] = max(mx[i], i + qry(i));
}
for(int i = 1; i<=n; ++i) printf("%lld ", mx[i]);
}
Compilation message
trading.cpp: In function 'int main()':
trading.cpp:15:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | int n, m; scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
trading.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d %d %d", &l, &r, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6608 KB |
Output is correct |
6 |
Correct |
2 ms |
6816 KB |
Output is correct |
7 |
Correct |
61 ms |
10568 KB |
Output is correct |
8 |
Correct |
67 ms |
11344 KB |
Output is correct |
9 |
Correct |
71 ms |
11344 KB |
Output is correct |
10 |
Correct |
78 ms |
11604 KB |
Output is correct |
11 |
Correct |
77 ms |
12372 KB |
Output is correct |
12 |
Correct |
87 ms |
12880 KB |
Output is correct |
13 |
Correct |
90 ms |
13140 KB |
Output is correct |
14 |
Correct |
94 ms |
13100 KB |
Output is correct |
15 |
Correct |
100 ms |
14096 KB |
Output is correct |
16 |
Correct |
105 ms |
14376 KB |
Output is correct |
17 |
Correct |
106 ms |
14368 KB |
Output is correct |
18 |
Correct |
108 ms |
14776 KB |
Output is correct |
19 |
Correct |
109 ms |
14416 KB |
Output is correct |
20 |
Correct |
126 ms |
16128 KB |
Output is correct |