Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int dp[216000];
Int l[216000], r[216000], a[216000];
Int n, m;
vector<P> Interval[216000];
vector<Int> add[216000], end[216000];
Int seg[1 << 20];
Int all[1 << 20];
void addval(Int l, Int r, Int val, Int bottom = 0, Int top = (1<<19), Int pos = 1){
  if(r <= bottom || top <= l)return;
  if(l <= bottom && top <= r){
    all[pos] += val;
    return;
  }
  Int mid = (bottom + top ) / 2;
  addval(l, r, val, bottom, mid, pos * 2);
  addval(l, r, val, mid, top, pos * 2+1);
  seg[pos] = max(seg[pos * 2] + all[pos * 2],
		 seg[pos * 2 + 1] + all[pos * 2 + 1]);
}

Int getval(Int l, Int r, Int bottom = 0, Int top = 1 << 19, Int pos = 1){
  if(r <= bottom || top <= l)return -INF;
  if(l <= bottom && top <= r){
    return seg[pos] + all[pos];
  }
  Int mid = (bottom + top) / 2;
  Int res = getval(l, r, bottom, mid, pos * 2);
  Int res2 = getval(l, r, mid, top, pos * 2 + 1);
  return max(res, res2) + all[pos];
}


int main(){
  cin >> n >> m;
  for(Int i = 0;i < m;i++){
    cin >> l[i] >> r[i] >> a[i];
    add[l[i]].push_back(i);
    end[r[i]].push_back(i);
  }
  dp[0] = 0;
  for(Int i = 1;i <= n;i++){
    for(Int j = 0;j < add[i].size();j++){
      Int id = add[i][j];
      addval(0, l[id], a[id]);
      //      cout << "add " << l[id] << " " << a[id] << endl;
    }
    dp[i] = getval(0, i);
    //    cout << i << " " << dp[i] << endl;
    for(Int j = 0;j < end[i].size();j++){
      Int id = end[i][j];
      addval(0, l[id], -a[id]);
      ///      cout << "add " << l[id] << " " << -a[id] << endl;
    }
    addval(i, i+1, dp[i]);
  }
  cout << getval(0,n+1) << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:5: error: reference to 'end' is ambiguous
   59 |     end[r[i]].push_back(i);
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/range_access.h:36:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:26:26: note:                 'std::vector<long long int> end [216000]'
   26 | vector<Int> add[216000], end[216000];
      |                          ^~~
a.cc:70:23: error: reference to 'end' is ambiguous
   70 |     for(Int j = 0;j < end[i].size();j++){
      |                       ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:26:26: note:                 'std::vector<long long int> end [216000]'
   26 | vector<Int> add[216000], end[216000];
      |                          ^~~
a.cc:71:16: error: reference to 'end' is ambiguous
   71 |       Int id = end[i][j];
      |                ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:26:26: note:                 'std::vector<long long int> end [216000]'
   26 | vector<Int> add[216000], end[216000];
      |                          ^~~