# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
690030 | moonhero | Trading (IZhO13_trading) | C++14 | 214 ms | 17356 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;
using ll = long long;
const int N = 3e5 + 5;
int r[N * 4], tc[N * 4], u[N * 4];
void push (int v, int tl, int tr) {
if (u[v]) {
int tm = (tl + tr) / 2;
u[v * 2] = max(u[v], u[v * 2]), u[v * 2 + 1] = max(u[v] + (tm - tl + 1), u[v * 2 + 1]);
u[v] = 0;
}
}
void upd (int v, int tl, int tr, int l, int r, int val) {
if (tl >= l && tr <= r) {
u[v] = max(u[v], val + tl - l);
return;
} if (tl > r || tr < l) return;
int tm = (tl + tr) / 2;
push(v, tl, tr);
upd(v * 2, tl, tm, l, r, val);
upd(v * 2 + 1, tm + 1, tr, l, r, val);
}
void out (int v, int tl, int tr) {
if (tl == tr) {
cout << u[v] << ' ';
return;
} int tm = (tl + tr) / 2;
push(v, tl, tr);
out(v * 2, tl, tm);
out(v * 2 + 1, tm + 1, tr);
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while (t--) {
int n; cin >> n;
for (int i = 0; i < N * 4; i++) r[i] = 0, u[i] = 0;
int q; cin >> q;
while (q--) {
int l, r, x; cin >> l >> r >> x;
upd(1, 1, n, l, r, x);
} out(1, 1, n);
} return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |