# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97465 | Kastanda | Trading (IZhO13_trading) | C++11 | 293 ms | 12764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |