# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81812 | mra2322001 | Trading (IZhO13_trading) | C++14 | 2 ms | 376 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 f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const int N = 300002;
struct data{
int ma;
} t[4*N];
int n, m;
void push(int k, int l, int r){
int mid = (l + r)/2;
if(l==r) return ;
t[k*2].ma = max(t[2*k].ma, t[k].ma);
t[k*2 + 1].ma = max(t[k].ma, t[k].ma + mid - l + 1);
}
void up(int k, int l, int r, int i, int j, int x){
push(k, l, r);
if(r < i || l > j) return ;
if(l >= i && r <= j){
int now = x + l - i;
t[k].ma = max(t[k].ma, now);
push(k, l, r);
return ;
}
int mid = (l + r)/2;
up(k*2, l, mid, i, j, x);
up(k*2 + 1, mid + 1, r, i, j, x);
}
int get1(int k, int l, int r, int i){
push(k, l, r);
if(l==r) return t[k].ma;
int mid = (l + r)/2;
if(i <= mid) return get1(k*2, l, mid, i);
return get1(k*2 + 1, mid + 1, r, i);
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
f1(i, 4*n) t[i].ma = INT_MIN;
while(m--){
int l, r, x; cin >> l >> r >> x;
up(1, 1, n, l, r, x);
}
f1(i, n) cout << get1(1, 1, n, i) << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |