Language: C++

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define int long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 2e5 + 10, inf = 1e18 + 10, mod = 1e9 + 7;
ll t[4 * N], c[4 * N], x[N], d[N], L[N], R[N], ans;
vector <int> a[N];
void push(int v, int tl, int tr)
{
    if(c[v])
    {
        t[v] += c[v];
        if (tl != tr){
            c[v + v] += c[v];
            c[v + v + 1] += c[v];
        }
        c[v] = 0;
    }
}
ll ma(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if(l <= tl && tr <= r)return t[v];
    else if(tr < l || r < tl)return -inf;
    else
    {
        int mid = (tl + tr) / 2;
        return max(ma(v + v, tl, mid, l, r), ma(v + v + 1, mid + 1, tr, l, r));
    }
}
void up(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if(l <= tl && tr <= r)
    {
        c[v] += val;
        push(v, tl, tr);
    }
    else if(tr < l || r < tl)return;
    else
    {
        int mid = (tl + tr) / 2;
        up(v + v, tl, mid, l, r, val);
        up(v + v + 1, mid + 1, tr, l, r, val);
        t[v] = max(t[v + v], t[v + v + 1]);
    }
}
main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        cin >> L[i] >> R[i] >> x[i];
        a[L[i]].pb(i);
        a[R[i]].pb(-i);
    }
    for(int i = 1; i <= n; i++)
    {
        for(auto j : a[i])
        {
            if(j > 0)up(1, 0, n, 0, i - 1, x[j]);
        }
        d[i] = ma(1, 0, n, 0, i - 1);
        up(1, 0, n, i, i, d[i]);
        for(auto j : a[i])
        {
            if(j < 0)
            {
                up(1, 0, n, 0, L[-j] - 1, -x[-j]);
            }
        }
        ans = max(ans , d[i]);
    }
    cout << ans;
}


Compiler output:
In file included from /usr/include/c++/14/ext/pb_ds/detail/type_utils.hpp:47,
                 from /usr/include/c++/14/ext/pb_ds/tag_and_trait.hpp:46,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:46,
                 from a.cc:10:
/usr/include/c++/14/tr1/type_traits:123:3: error: redefinition of 'struct std::tr1::__is_integral_helper<long long int>'
  123 |   _DEFINE_SPEC(0, __is_integral_helper, long long, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:117:3: note: previous definition of 'struct std::tr1::__is_integral_helper<long long int>'
  117 |   _DEFINE_SPEC(0, __is_integral_helper, int, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:124:3: error: redefinition of 'struct std::tr1::__is_integral_helper<long long unsigned int>'
  124 |   _DEFINE_SPEC(0, __is_integral_helper, unsigned long long, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:118:3: note: previous definition of 'struct std::tr1::__is_integral_helper<long long unsigned int>'
  118 |   _DEFINE_SPEC(0, __is_integral_helper, unsigned int, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:554:3: error: redefinition of 'struct std::tr1::__is_signed_helper<long long int>'
  554 |   _DEFINE_SPEC(0, __is_signed_helper, long long, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:552:3: note: previous definition of 'struct std::tr1::__is_signed_helper<long long int>'
  552 |   _DEFINE_SPEC(0, __is_signed_helper, int, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:569:3: error: redefinition of 'struct std::tr1::__is_unsigned_helper<long long unsigned int>'
  569 |   _DEFINE_SPEC(0, __is_unsigned_helper, unsigned long long, true)
      |   ^
/usr/include/c++/14/tr1/type_traits:567:3: note: previous definition of 'struct std::tr1::__is_unsigned_helper<long long unsigned int>'
  567 |   _DEFINE_SPEC(0, __is_unsigned_helper, unsigned int, true)
      |   ^
In file included from /usr/include/c++/14/tr1/functional:43,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:51,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:47:
/usr/include/c++/14/tr1/functional_hash.h:82:3: error: redefinition of 'std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long int; std::size_t = long unsigned int]'
   82 |   _TR1_hashtable_define_trivial_hash(long long)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/functional_hash.h:80:3: note: 'std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long int; std::size_t = long unsigned int]' previously declared here
   80 |   _TR1_hashtable_define_trivial_hash(int)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/functional_hash.h:86:3: error: redefinition of 'std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long unsigned int; std::size_t = long unsigned int]'
   86 |   _TR1_hashtable_define_trivial_hash(unsigned long long)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/functional_hash.h:84:3: note: 'std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long unsigned int; std::size_t = long unsigned int]' previously declared here
   84 |   _TR1_hashtable_define_trivial_hash(unsigned int)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main()
      | ^~~~