# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
538890 | GioChkhaidze | Trading (IZhO13_trading) | C++14 | 177 ms | 12620 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;
const int N = 3e5 + 5;
int n, m, L, R, X, inf = 1e9;
vector < int > v(4 * N, -inf);
void upd(int h, int l, int r) {
if (r < L || R < l) return ;
if (L <= l && r <= R) {
v[h] = max(v[h], X - L);
return ;
}
upd((h << 1), l, ((l + r) >> 1));
upd(((h << 1) | 1), ((l + r) >> 1) + 1, r);
}
void dfs(int h, int l, int r, int mx) {
if (l == r) {
if (mx == -inf)
cout << 0 << " ";
else
cout << l + mx << " ";
return ;
}
dfs((h << 1), l, ((l + r) >> 1), max(mx, v[(h << 1)]));
dfs(((h << 1) | 1), ((l + r) >> 1) + 1, r, max(mx, v[((h << 1) | 1)]));
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> L >> R >> X;
upd(1, 1, n);
}
dfs(1, 1, n, v[1]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |