# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49779 | mra2322001 | Trading (IZhO13_trading) | C++14 | 474 ms | 68224 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;
int n, lazy[N*4], lo, hi, price;
int t[4*N];
void push(int k, int l, int r){
int x = lazy[k];
if(!x) return ;
t[k] = max(t[k], x);
lazy[k] = 0;
if(l != r){
int m = (l + r)/2;
/// l
lazy[k << 1] = max(lazy[k << 1], x);
/// m + 1
lazy[k << 1 | 1] = max(lazy[k << 1 | 1], x+ m - l + 1);
}
}
void up(int k, int l, int r){
push(k, l, r);
if(r < lo || l > hi) return ;
if(l >= lo && r <= hi){
lazy[k] = max(price + l - lo, lazy[k]);
push(k, l, r);
return ;
}
int m = (l + r)/2;
up(k << 1, l, m);
up(k << 1 | 1, m + 1, r);
t[k] = max(t[k << 1], t[k << 1 | 1]);
}
int get1(int k, int l, int r, int i){
push(k, l, r);
if(l==r) return t[k];
int m = (l + r)/2;
if(i >= l && i <= m) return get1(k << 1, l, m, i);
return get1(k << 1 | 1, m + 1, r, i);
}
int main(){
ios_base::sync_with_stdio(0);
int q; cin >> n >> q;
while(q--){
cin >> lo >> hi >> price;
up(1, 1, n);
}
f1(i, n) cout << get1(1, 1, n, i) << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |