# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440797 | parsabahrami | Trading (IZhO13_trading) | C++17 | 306 ms | 12632 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.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
#define lc id << 1
#define rc lc | 1
const int N = 3e5 + 10, MOD = 1e9 + 7;
int seg[N << 2], n, q;
void upd(int ql, int qr, int x, int id = 1, int l = 1, int r = n + 1) {
if (qr <= l || r <= ql) return;
if (ql <= l && r <= qr) { seg[id] = max(seg[id], l - ql + x); return; }
int md = (l + r) >> 1;
upd(ql, qr, x, lc, l, md), upd(ql, qr, x, rc, md, r);
}
int get(int p, int id = 1, int l = 1, int r = n + 1) {
if (r - l < 2) return seg[id];
int md = (l + r) >> 1;
return max(seg[id] + p - l, p < md ? get(p, lc, l, md) : get(p, rc, md, r));
}
int main() {
fill(seg, seg + N * 4, -MOD);
scanf("%d%d", &n, &q);
for (; q; q--) {
int l, r, x; scanf("%d%d%d", &l, &r, &x);
upd(l, r + 1, x);
}
for (int i = 1; i <= n; i++)
printf("%d ", max(0, get(i)));
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |