# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21856 | ulna | Trading (IZhO13_trading) | C++11 | 216 ms | 4364 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;
// why am I so weak
int n, m;
int dat[600055];
void update(int l, int r, int val) {
l += n, r += n;
for (; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
dat[l] = max(dat[l], val);
l++;
}
if (r & 1) {
r--;
dat[r] = max(dat[r], val);
}
}
}
int query(int id) {
int res = -INT_MAX;
for (id += n; id > 0; id >>= 1) {
res = max(res, dat[id]);
}
return res;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n + n; i++) {
dat[i] = -INT_MAX;
}
while (m--) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
x--;
update(x, y, z - x);
}
for (int i = 0; i < n; i++) {
if (i) printf(" ");
int res = query(i);
if (res == -INT_MAX) res = 0;
else res += i;
printf("%d", res);
}
puts("");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |