Language: C++

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

template <class T>
class SegmentTree {
    long long n; // 葉の数
    vector<T> data;  // データを格納する配列
    T def;  // 初期値（単位元）
    function<T(T, T)> operation;  // 区間クエリで使う処理
    function<T(T, T)> update;  // 点更新で使う処理

    T _query(long long a, long long b, long long k, long long l, long long r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return data[k];  // a,l,r,bの順で含まれる
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)>>1);
            T c2 = _query(a, b, 2*k+2, (l+r)>>1, r);
            return operation(c1, c2);
        }
    }

public:
    SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
            n = 1;
            while (n < _n) n<<=1;
            data = vector<T>(2*n-1, def);
        }
    
    void change(long long i, T x) {
        i += n-1;
        data[i] = update(data[i], x);
        while (i>0) {
            i = (i-1)>>1;
            data[i] = operation(data[i*2+1], data[i*2+2]);
        }
    }

    T query(long long a, long long b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](long long i) {
        return data[i+n-1];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll h(n), a(n);
    REP(i, n) cin >> h[i];
    REP(i, n) cin >> a[i];
    SegmentTree<ll> seg(n+1, 0LL, 
                        [](ll a, ll b){return max(a, b);},
                        [](ll a, ll b){return b;});
    REP(i, n) {
        ll tmp = seg.query(0, h[i]);
        seg.change(h[i], tmp+a[i]);
    }
    cout << seg.query(0, n+1) << '\n';
    return 0;
}


Compiler output:
a.cc:42:5: error: 'function' does not name a type; did you mean 'union'?
   42 |     function<T(T, T)> operation;  // 区間クエリで使う処理
      |     ^~~~~~~~
      |     union
a.cc:43:5: error: 'function' does not name a type; did you mean 'union'?
   43 |     function<T(T, T)> update;  // 点更新で使う処理
      |     ^~~~~~~~
      |     union
a.cc:56:36: error: 'function' has not been declared
   56 |     SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
      |                                    ^~~~~~~~
a.cc:56:44: error: expected ',' or '...' before '<' token
   56 |     SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
      |                                            ^
a.cc: In constructor 'SegmentTree<T>::SegmentTree(size_t, T, int)':
a.cc:57:22: error: class 'SegmentTree<T>' does not have any field named 'operation'
   57 |         : def(_def), operation(_operation), update(_update) {
      |                      ^~~~~~~~~
a.cc:57:32: error: '_operation' was not declared in this scope
   57 |         : def(_def), operation(_operation), update(_update) {
      |                                ^~~~~~~~~~
a.cc:57:45: error: class 'SegmentTree<T>' does not have any field named 'update'
   57 |         : def(_def), operation(_operation), update(_update) {
      |                                             ^~~~~~
a.cc:57:52: error: '_update' was not declared in this scope
   57 |         : def(_def), operation(_operation), update(_update) {
      |                                                    ^~~~~~~
a.cc: In function 'int main()':
a.cc:90:50: error: no matching function for call to 'SegmentTree<long long int>::SegmentTree(ll, long long int, main()::<lambda(ll, ll)>, main()::<lambda(ll, ll)>)'
   90 |                         [](ll a, ll b){return b;});
      |                                                  ^
a.cc:56:5: note: candidate: 'SegmentTree<T>::SegmentTree(size_t, T, int) [with T = long long int; size_t = long unsigned int]'
   56 |     SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
      |     ^~~~~~~~~~~
a.cc:56:5: note:   candidate expects 3 arguments, 4 provided
a.cc:38:7: note: candidate: 'SegmentTree<long long int>::SegmentTree(const SegmentTree<long long int>&)'
   38 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:38:7: note:   candidate expects 1 argument, 4 provided
a.cc:38:7: note: candidate: 'SegmentTree<long long int>::SegmentTree(SegmentTree<long long int>&&)'
a.cc:38:7: note:   candidate expects 1 argument, 4 provided
a.cc: In instantiation of 'void SegmentTree<T>::change(long long int, T) [with T = long long int]':
a.cc:93:19:   required from here
   93 |         seg.change(h[i], tmp+a[i]);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:65:25: error: 'update' was not declared in this scope
   65 |         data[i] = update(data[i], x);
      |                   ~~~~~~^~~~~~~~~~~~
a.cc:68:32: error: 'operation' was not declared in this scope
   68 |             data[i] = operation(data[i*2+1], data[i*2+2]);
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'T SegmentTree<T>::_query(long long int, long long int, long long int, long long int, long long int) [with T = long long int]':
a.cc:73:16:   required from 'T SegmentTree<T>::query(long long int, long long int) [with T = long long int]'
   73 |         return _query(a, b, 0, 0, n);
      |                ^~~~~~
a.cc:92:27:   required from here
   92 |         ll tmp = seg.query(0, h[i]);
      |                  ~~~~~~~~~^~~~~~~~~
a.cc:51:29: error: 'operation' was not declared in this scope
   51 |             return operation(c1, c2);
      |                    ~~~~~~~~~^~~~~~~~