# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673593 | moday_morning | Trading (IZhO13_trading) | C++17 | 167 ms | 13620 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>
#define int long long
using namespace std;
const int N = 500005;
int n, m, l, r, x, seg[4 * N], ans[N];
void update (int node, int L, int R, int l, int r) {
if (L > r || l > R) {
return;
}
if (l <= L && r >= R) {
seg[node] = max(seg[node], x);
return;
}
int mid = (L + R)/2;
update(node * 2, L, mid, l, r);
update(node * 2 + 1, mid + 1, R, l, r);
}
void res (int node, int l, int r) {
if (l == r){
ans[l] = seg[node];
return;
}
int mid = (l + r)/2;
seg[node * 2] = max(seg[node], seg[node * 2]);
res(node * 2, l, mid);
seg[node * 2 + 1] = max(seg[node], seg[node * 2 + 1]);
res(node * 2 + 1, mid + 1, r);
}
void solve () {
cin >> n>> m;
for (int i = 0;i < 4 * n;i++) seg[i] = -1e9;
while (m--){
cin >> l>> r>> x;
x -= (l - 1);
update(1, 1, n, l, r);
}
res(1, 1, n);
for (int i = 0; i < n; i++) {
cout << max(ans[i + 1] + i, 0LL) << " ";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |