# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988072 |
2024-05-24T03:04:06 Z |
long |
Trading (IZhO13_trading) |
C++17 |
|
397 ms |
47228 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 3e5 + 10;
int seg[N * 4], laz[N * 4];
void push(int id) {
int &t = laz[id];
laz[id * 2] += t;
laz[id * 2 + 1] += t;
seg[id * 2] += t;
seg[id * 2 + 1] += t;
t = 0;
}
void upd(int id, int l, int r, int u, int v, int c) {
if (l > v || r < u)
return;
if (l >= u && r <= v) {
laz[id] += c;
seg[id] += c;
return;
}
push(id);
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, c);
upd(id * 2 + 1, m + 1, r, u, v, c);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
void run(int id, int l, int r, int p, int v) {
if (l > p || r < p)
return;
if (l == r) {
seg[id] = v;
laz[id] = 0;
return;
}
push(id);
int m = (l + r) / 2;
run(id * 2, l, m, p, v);
run(id * 2 + 1, m + 1, r, p, v);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
vector <int> event[N];
int l[N], r[N], v[N];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
seg[1] = laz[1] = -1e8;
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> l[i] >> r[i] >> v[i];
event[l[i]].pb(i);
event[r[i] + 1].pb(-i);
}
for (int i = 1; i <= n; i++) {
upd(1, 1, m, 1, m, 1);
for (auto x : event[i]) {
if (x > 0) {
run(1, 1, m, x, v[x]);
} else {
run(1, 1, m, -x, -1e8);
}
}
cout << max(0LL, seg[1]) << " ";
}
return 0;
}
Compilation message
trading.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8028 KB |
Output is correct |
2 |
Correct |
3 ms |
8124 KB |
Output is correct |
3 |
Correct |
3 ms |
8228 KB |
Output is correct |
4 |
Correct |
4 ms |
8540 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
5 ms |
8540 KB |
Output is correct |
7 |
Correct |
170 ms |
28236 KB |
Output is correct |
8 |
Correct |
196 ms |
30064 KB |
Output is correct |
9 |
Correct |
162 ms |
30260 KB |
Output is correct |
10 |
Correct |
167 ms |
30012 KB |
Output is correct |
11 |
Correct |
202 ms |
32576 KB |
Output is correct |
12 |
Correct |
243 ms |
32576 KB |
Output is correct |
13 |
Correct |
269 ms |
33252 KB |
Output is correct |
14 |
Correct |
218 ms |
32544 KB |
Output is correct |
15 |
Correct |
284 ms |
35136 KB |
Output is correct |
16 |
Correct |
300 ms |
35864 KB |
Output is correct |
17 |
Correct |
254 ms |
34752 KB |
Output is correct |
18 |
Correct |
304 ms |
43452 KB |
Output is correct |
19 |
Correct |
267 ms |
35772 KB |
Output is correct |
20 |
Correct |
397 ms |
47228 KB |
Output is correct |