Genome Evolution LA5052


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;

const int MAXN(3010);

int arr1[MAXN], arr2[MAXN];
int pos[MAXN];

int main()
{
	int n;
	while(scanf("%d", &n), n)
	{
		for(int i = 1; i <= n; ++i)
			scanf("%d", arr1+i);
		for(int i = 1; i <= n; ++i)
			scanf("%d", arr2+i);
		for(int i = 1; i <= n; ++i)
			pos[arr2[i]] = i;
		int mi, mx;
		int ans = 0;
		for(int i = 1; i <= n; ++i)
		{
			mi = mx = pos[arr1[i]];
			for(int j = i+1; j <= n; ++j)
			{
				int temp = pos[arr1[j]];
				if(temp > mx)
					mx = temp;
				if(temp < mi)
					mi = temp;
				if(mx-mi == j-i)
					++ans;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


你可能感兴趣的:(Genome Evolution LA5052)