1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;

typedef pair<int,int> par;
long long n, k, uf[100009], tab[2][100009], wyn[200009];
par invtab[200009], moves[3] = {{1, 0}, {0, 1}, {0, -1}};

int find(int u)
{
	return (uf[u] == u ? u : uf[u] = find(uf[u]));
}

void Union(int x, int y)
{
	uf[find(x)] = find(y);
	return;
}

void solve(int x)
{
	int w = 0, a, b, c;
	par p;
	for(int i=x; i<=2*n; i++) uf[i] = i;
	for(int i=x; i<=2*n; i++)
	{
		c = 1;
		for(int j=0; j<3; j++)
		{
			a = (invtab[i].fi + moves[j].fi) % 2;
			b = (invtab[i].se + moves[j].se) % n;
			if(b < 0) b += n;
			if(tab[a][b] >= x && tab[a][b] < i && find(tab[a][b]) != find(i))
			{
				Union(tab[a][b], i);
				c--;
			}
		}
		w += c;
		wyn[w]++;
	}
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>k;
	for(int i=0; i<=1; i++) 
	{
		for(int j=0; j<n; j++) 
		{
			cin>>tab[i][j];
			invtab[tab[i][j]] = par(i, j);
		}
	}
	for(int i=1; i<=2*n; i++) solve(i);
	for(int i=1; i<=k; i++) cout<<wyn[i]<<" ";
	return 0;
}