Submission #894346

# Submission time Handle Problem Language Result Execution time Memory
894346 2023-12-28T07:00:24 Z raul2008487 Trading (IZhO13_trading) C++17
0 / 100
1 ms 604 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 int sz = 3e5+5;
const int mod = 998244353;
const ll inf = 1000000000000000;
bool inran(ll x, ll l, ll r){
    return x <= r && x >= l;
}
struct Segtree{
    ll sz;
    vl st, res;
    void init(ll n){
        sz = 1;
        while(sz < n){
            sz <<= 1;
        }
        res.resize(n+1);
        st.assign(sz<<1, 0);
        //lazy.assign(sz<<1, 0);
    }
    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;
            }
            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 print(ll n){
        ll i;
        for(i=1;i<=n;i++){
            cout << res[i] << ' ';
        }cout << endl;
        return ;
    }
};
void solve()
{
    Segtree st;
    ll n, m, i, j;
    cin>>n>>m;
    st.init(n);
    vl l(n), r(n), x(n);
    for(i=0;i<m;i++){
        cin>>l[i]>>r[i]>>x[i];
        st.update(1, 1, n, l[i], r[i], x[i]);
    }
    st.trav(1, 1, n);
    st.print(n);

}
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:76:17: warning: unused variable 'j' [-Wunused-variable]
   76 |     ll n, m, i, j;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -