tmlrock @ 2024-04-19 21:01:10
#include<bits/stdc++.h>
using namespace std;
using i16 = short;
using i32 = int;
using i64 = long long;
using u16 = unsigned short;
using u32 = unsigned;
using u64 = unsigned long long;
using f128 = long double;
using f64 = double;
using f32 = float;
int dp[1000005];
int a[2][1000005];
int pre[1000005];//a[0]
inline void solving(int n) {
memset(pre, -1, sizeof pre);
for (int i = 0; i < n; ++i) {
pre[a[0][i]] = i;
dp[i] = dp[i - 1];
if (~pre[a[1][i]])dp[i] = max(dp[i], dp[pre[a[1][i]]] + 1);
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i)cin >> a[0][i];
for (int i = 0; i < n; ++i)cin >> a[1][i];
solving(n);
cout<<dp[n-1];
return 0;
}
by OldDriverTree @ 2024-04-19 21:05:31
@tmlrock hack:
5
1 2 3 4 5
3 4 5 1 2
by tmlrock @ 2024-04-19 21:10:17
@OldDriverTree thanks