// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, q, best[N * 4];
void Add(int le, int ri, int st, int id = 1, int l = 0, int r = n)
{
if (ri <= l || r <= le)
return ;
if (le <= l && r <= ri)
{
best[id] = max(best[id], st + l - le);
return ;
}
Add(le, ri, st, id + id, l, (l + r) >> 1);
Add(le, ri, st, id + id + 1, (l + r) >> 1, r);
}
void DFS(int id = 1, int l = 0, int r = n)
{
if (r - l < 2)
{
printf("%d ", max(best[id], 0));
return ;
}
best[id + id] = max(best[id + id], best[id]);
best[id + id + 1] = max(best[id + id + 1], best[id] + ((l + r) >> 1) - l);
DFS(id + id, l, (l + r) >> 1);
DFS(id + id + 1, (l + r) >> 1, r);
}
int main()
{
scanf("%d%d", &n, &q);
memset(best, -63, sizeof(best));
for (; q; q --)
{
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
Add(l - 1, r, x);
}
DFS();
return 0;
}
Compilation message
trading.cpp: In function 'int main()':
trading.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~
trading.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l, &r, &x);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4980 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
167 ms |
8788 KB |
Output is correct |
8 |
Correct |
156 ms |
9424 KB |
Output is correct |
9 |
Correct |
158 ms |
9352 KB |
Output is correct |
10 |
Correct |
190 ms |
9464 KB |
Output is correct |
11 |
Correct |
199 ms |
10104 KB |
Output is correct |
12 |
Correct |
214 ms |
10312 KB |
Output is correct |
13 |
Correct |
223 ms |
10632 KB |
Output is correct |
14 |
Correct |
187 ms |
10360 KB |
Output is correct |
15 |
Correct |
221 ms |
11128 KB |
Output is correct |
16 |
Correct |
252 ms |
11260 KB |
Output is correct |
17 |
Correct |
230 ms |
11400 KB |
Output is correct |
18 |
Correct |
248 ms |
11784 KB |
Output is correct |
19 |
Correct |
266 ms |
11512 KB |
Output is correct |
20 |
Correct |
293 ms |
12764 KB |
Output is correct |