Submission #894357

# Submission time Handle Problem Language Result Execution time Memory
894357 2023-12-28T07:10:01 Z raul2008487 Trading (IZhO13_trading) C++17
0 / 100
23 ms 65536 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const ll sz = 2e6+5;
const int mod = 998244353;
const ll inf = 1000000000000000;
ll res[sz];
vl st(sz<<2);
bool inran(ll x, ll l, ll r){
    return x <= r && x >= l;
}
void push(ll v, ll tl, ll tr){
    if(tl == tr || (!st[v])){return ;}
    ll tm = (tl + tr)>>1;
        st[v*2] = max(st[v*2], st[v]);
        st[v*2+1] = max(st[v*2+1], st[v] + tm - tl + 1);
        st[v] = 0;
    }
void update(ll v, ll tl, ll tr, ll l, ll r, ll val){
    if(tl > r || tr < l){return ;}
    if(tl >= l && tr <= r){
        ll nl = val + tl - l;
        st[v] = max(st[v], nl);
        if(st[v]){
            //cout << tl << ' ' << tr << ' ' << st[v] << endl;
        }
        push(v, tl, tr);
        return ;
    }
    push(v, tl, tr);
    ll tm = (tl + tr)>>1;
    update(v*2, tl, tm, l, r, val);
    update(v*2+1, tm+1, tr, l, r, val);
}
void trav(ll v, ll l, ll r){
    if(l == r){
        res[l] = st[v];
        return ;
    }
    push(v, l, r);
    ll m = (l + r)>>1;
    trav(v*2, l, m);
    trav(v*2+1, m+1, r);
}
void solve()
{
    ll n, m, i, j;
    cin>>n>>m;
    vl l(n), r(n), x(n);
    for(i=0;i<m;i++){
        cin>>l[i]>>r[i]>>x[i];
        update(1, 1, n, l[i], r[i], x[i]);
    }
    trav(1, 1, n);
    for(i=1;i<=n;i++){
        cout << res[i] << ' ';
    }cout << endl;


}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //precomp();
    ll tst=1;
    //cin>>tst;
    while(tst--){
        solve();
    }
}
/*
4
6
5 4 3 2 1 0
3
2 1 0
8
2 3 6 7 0 1 4 5
1
0


*/

Compilation message

trading.cpp: In function 'void solve()':
trading.cpp:58:17: warning: unused variable 'j' [-Wunused-variable]
   58 |     ll n, m, i, j;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 63064 KB Output is correct
2 Correct 8 ms 63068 KB Output is correct
3 Runtime error 23 ms 65536 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -