#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], b[N], pos[N], ans[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= n; i ++)
cin >> b[i];
for (int i = 1; i <= n; i ++)
pos[b[i]] = i;
for (int i = 1; i <= n; i ++)
if (pos[i] < i)
ans[i] = pos[i] + n - i + 1;
else
ans[i] = pos[i] - i;
int res = 0;
for (int i = 1; i <= n; i ++)
res = max(res, ans[i]);
bool flag = true;
while (flag)
{
flag = false;
for (int i = 1; i <= n; i ++)
if (pos[i])
{
if (res > ans[i])
ans[i] = pos[i] + n - i + 1;
if (res < ans[i])
res = ans[i], flag = true;
}
}
cout << res << '\n';
}
02-22
582
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交