Language: C++

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;

class SegTree {
public:
	//Range Max Query
	vector<int> ar;
	int length;
	SegTree(int n) {
		length = 1;
		while (n > length)length *= 2;
		ar.resize(2 * length - 1);
		for (int i = 0; i < 2 * length - 1; i++)ar[i] = 0;
	}

	void update(int k, int a) {
		//k番目をaにする
		k += length - 1;
		ar[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			ar[k] = max(ar[2 * k + 1], ar[2 * k + 2]);
		}
	}

	int getval(int a, int b, int k, int l, int r) {
		//[a, b)を求める
		if (r <= a || b <= l)return 0;
		else if (a <= l && r <= b)return ar[k];
		else {
			int v1, v2;
			v1 = getval(a, b, 2 * k + 1, l, (l + r) / 2);
			v2 = getval(a, b, 2 * k + 2, (l + r) / 2, r);
			return max(v1, v2);
		}
	}

};

int N;
ll dp[200001];//dp[i]:=高さiで終わる際の美しさの和の最大値
ll H[200001], I[200001];
ll pos1[200001];

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
		pos1[H[i]] = i;
	}
	for (int i = 1; i <= N; i++) {
		cin >> I[i];
	}

	SegTree st(N + 1);

	dp[0] = 0;
	for (int i = 1; i <= N; i++) {

		dp[i] = st.getval(0, pos1[i], 0, 0, st.length) + I[pos1[i]];//[0, i)の中の最大値をlog nで求める。0番は便宜上の配置であり、実際は1,2...番の順にデータが格納される
		st.update(pos1[i], dp[i]);
	} 
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	
	return 0;
}#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;

class SegTree {
public:
	//Range Max Query
	vector<int> ar;
	int length;
	SegTree(int n) {
		length = 1;
		while (n > length)length *= 2;
		ar.resize(2 * length - 1);
		for (int i = 0; i < 2 * length - 1; i++)ar[i] = 0;
	}

	void update(int k, int a) {
		//k番目をaにする
		k += length - 1;
		ar[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			ar[k] = max(ar[2 * k + 1], ar[2 * k + 2]);
		}
	}

	int getval(int a, int b, int k, int l, int r) {
		//[a, b)を求める
		if (r <= a || b <= l)return 0;
		else if (a <= l && r <= b)return ar[k];
		else {
			int v1, v2;
			v1 = getval(a, b, 2 * k + 1, l, (l + r) / 2);
			v2 = getval(a, b, 2 * k + 2, (l + r) / 2, r);
			return max(v1, v2);
		}
	}

};

int N;
ll dp[200001];//dp[i]:=高さiで終わる際の美しさの和の最大値
ll H[200001], I[200001];
ll pos1[200001];

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
		pos1[H[i]] = i;
	}
	for (int i = 1; i <= N; i++) {
		cin >> I[i];
	}

	SegTree st(N + 1);

	dp[0] = 0;
	for (int i = 1; i <= N; i++) {

		dp[i] = st.getval(0, pos1[i], 0, 0, st.length) + I[pos1[i]];//[0, i)の中の最大値をlog nで求める。0番は便宜上の配置であり、実際は1,2...番の順にデータが格納される
		st.update(pos1[i], dp[i]);
	} 
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	
	return 0;
}

Compiler output:
a.cc:75:2: error: stray '#' in program
   75 | }#include<iostream>
      |  ^
a.cc:75:3: error: 'include' does not name a type
   75 | }#include<iostream>
      |   ^~~~~~~
a.cc:82:7: error: redefinition of 'class SegTree'
   82 | class SegTree {
      |       ^~~~~~~
a.cc:8:7: note: previous definition of 'class SegTree'
    8 | class SegTree {
      |       ^~~~~~~
a.cc:118:5: error: redefinition of 'int N'
  118 | int N;
      |     ^
a.cc:44:5: note: 'int N' previously declared here
   44 | int N;
      |     ^
a.cc:119:4: error: redefinition of 'll dp [200001]'
  119 | ll dp[200001];//dp[i]:=高さiで終わる際の美しさの和の最大値
      |    ^~
a.cc:45:4: note: 'll dp [200001]' previously declared here
   45 | ll dp[200001];//dp[i]:=高さiで終わる際の美しさの和の最大値
      |    ^~
a.cc:120:4: error: redefinition of 'll H [200001]'
  120 | ll H[200001], I[200001];
      |    ^
a.cc:46:4: note: 'll H [200001]' previously declared here
   46 | ll H[200001], I[200001];
      |    ^
a.cc:120:15: error: redefinition of 'll I [200001]'
  120 | ll H[200001], I[200001];
      |               ^
a.cc:46:15: note: 'll I [200001]' previously declared here
   46 | ll H[200001], I[200001];
      |               ^
a.cc:121:4: error: redefinition of 'll pos1 [200001]'
  121 | ll pos1[200001];
      |    ^~~~
a.cc:47:4: note: 'll pos1 [200001]' previously declared here
   47 | ll pos1[200001];
      |    ^~~~
a.cc:123:5: error: redefinition of 'int main()'
  123 | int main() {
      |     ^~~~
a.cc:49:5: note: 'int main()' previously defined here
   49 | int main() {
      |     ^~~~