Language: C++

#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>

using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;

#define MOD 1000000007


struct data {
  long long a;
};
const long long minint = 0;
data resetdata = {minint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, long long newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  long long pick(int a, int b, int k = 0, int l = 0,
                 int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return minint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    long long nowl, nowr, nextlr = k * 2 + 1,
                          med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return max(nowl, nowr);
  }
};

int main()
{
    int n;
    cin >> n;
    int h[n];
    ll a[n];
    REP(i, 0, n)
    {
        cin >> h[i];
    }
    REP(i, 0, n)
    {
        cin >> a[i];
    }
    ll ans = 0;

    RMQ rmq = RMQ(n + 1);
    REP(i,0,n){
        ll now = a[i];
        now += rmq.pick(0, h[i]);
        rmq.update(h[i], now);
        ans = max(ans, now);
    }
    cout << ans << endl;

    return 0;
}
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>

using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;

#define MOD 1000000007


struct data {
  long long a;
};
const long long minint = 0;
data resetdata = {minint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, long long newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  long long pick(int a, int b, int k = 0, int l = 0,
                 int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return minint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    long long nowl, nowr, nextlr = k * 2 + 1,
                          med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return max(nowl, nowr);
  }
};

int main()
{
    int n;
    cin >> n;
    int h[n];
    ll a[n];
    REP(i, 0, n)
    {
        cin >> h[i];
    }
    REP(i, 0, n)
    {
        cin >> a[i];
    }
    ll ans = 0;

    RMQ rmq = RMQ(n + 1);
    REP(i,0,n){
        ll now = a[i];
        now += rmq.pick(0, h[i]);
        rmq.update(h[i], now);
        ans = max(ans, now);
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:26:1: error: reference to 'data' is ambiguous
   26 | data resetdata = {minint};
      | ^~~~
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:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:30:14: error: template argument 1 is invalid
   30 |   vector<data> dat;
      |              ^
a.cc:30:14: error: template argument 2 is invalid
a.cc:31:21: error: reference to 'data' is ambiguous
   31 |   RMQ(int newn = 1, data resets = resetdata) {
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:31:21: error: 'data' has not been declared
   31 |   RMQ(int newn = 1, data resets = resetdata) {
      |                     ^~~~
a.cc:34:28: error: reference to 'data' is ambiguous
   34 |   void reset(int newn = 1, data resets = resetdata) {
      |                            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:34:28: error: 'data' has not been declared
   34 |   void reset(int newn = 1, data resets = resetdata) {
      |                            ^~~~
a.cc:31:35: error: 'resetdata' was not declared in this scope
   31 |   RMQ(int newn = 1, data resets = resetdata) {
      |                                   ^~~~~~~~~
a.cc:34:42: error: 'resetdata' was not declared in this scope
   34 |   void reset(int newn = 1, data resets = resetdata) {
      |                                          ^~~~~~~~~
a.cc: In member function 'void RMQ::reset(int, int)':
a.cc:37:9: error: request for member 'resize' in '((RMQ*)this)->RMQ::dat', which is of non-class type 'int'
   37 |     dat.resize(2 * sizen - 1);
      |         ^~~~~~
a.cc:38:28: error: request for member 'size' in '((RMQ*)this)->RMQ::dat', which is of non-class type 'int'
   38 |     for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
      |                            ^~~~
a.cc:38:44: error: invalid types 'int[int]' for array subscript
   38 |     for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
      |                                            ^
a.cc: In member function 'bool RMQ::update(int, long long int)':
a.cc:44:8: error: invalid types 'int[int]' for array subscript
   44 |     dat[k].a = newnum;
      |        ^
a.cc:47:10: error: invalid types 'int[int]' for array subscript
   47 |       dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
      |          ^
a.cc:47:25: error: invalid types 'int[int]' for array subscript
   47 |       dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
      |                         ^
a.cc:47:43: error: invalid types 'int[int]' for array subscript
   47 |       dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
      |                                           ^
a.cc: In member function 'long long int RMQ::pick(int, int, int, int, int)':
a.cc:60:36: error: invalid types 'int[int]' for array subscript
   60 |     if(a <= l && r <= b) return dat[k].a;
      |                                    ^
a.cc: At global scope:
a.cc:118:8: error: redefinition of 'struct data'
  118 | struct data {
      |        ^~~~
a.cc:22:8: note: previous definition of 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:121:17: error: redefinition of 'const long long int minint'
  121 | const long long minint = 0;
      |                 ^~~~~~
a.cc:25:17: note: 'const long long int minint' previously defined here
   25 | const long long minint = 0;
      |                 ^~~~~~
a.cc:122:1: error: reference to 'data' is ambiguous
  122 | data resetdata = {minint};
      | ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:123:8: error: redefinition of 'struct RMQ'
  123 | struct RMQ {
      |        ^~~
a.cc:27:8: note: previous definition of 'struct RMQ'
   27 | struct RMQ {
      |        ^~~
a.cc:166:5: error: redefinition of 'int main()'
  166 | int main()
      |     ^~~~
a.cc:70:5: note: 'int main()' previously defined here
   70 | int main()
      |     ^~~~