#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 3007;
int a[maxn], b[maxn], pos[maxn], n;
int main()
{
while (cin >> n && n) {
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
cin >> b[i];
pos[b[i]] = i;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int l = pos[a[i]], r = l,len = 1;
for (int j = i + 1; j < n; j++) {
l = min(l, pos[a[j]]);
r = max(r, pos[a[j]]);
++len;
if (r - l + 1 == len)++ans;
}
}
cout << ans << endl;
}
return 0;
}
uva1481
最新推荐文章于 2024-11-04 23:24:03 发布