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
#include <iostream>
using namespace std;
int t[200004];
int spojna[105][10005];
int pol[200005];
int ile_ciek[13];
//int cur = 1;
void dfs(int v, int n, int licz, int l, int r, int cur)
{
    spojna[v][licz] = cur;
    if (l <= t[(v-2)%n] && t[(v-2)%n] <= r && spojna[(v-2)%n][licz] == 0){
        dfs((v-2)%n, n, licz, l, r, cur);
    }
    if (l <= t[(v+2)%n] && t[(v+2)%n] <= r && spojna[(v+2)%n][licz] == 0){
        dfs((v+2)%n, n, licz, l, r, cur);
    }
    if (v&1 && l <= t[v-1] && t[v-1] <= r && spojna[v-1][licz] == 0){
        dfs(v-1, n, licz, l , r, cur);
    }
    if (!(v&1) && l <= t[v+1] && t[v+1] <= r &&  spojna[v+1][licz] == 0){
        dfs(v+1, n, licz, l, r, cur);
    }

}
int main()
{
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> t[2*i];
        pol[t[2*i]] = 2*i;
    }
    for (int i = 0; i < n; i++){
        cin >> t[2*i+1];
        pol[t[2*i+1]] = 2*i + 1;
    }
    int licz = 0, cur;
    long long sum = 0;
    for (int i = 1; i <= 2*n; i++)
    {
        for (int j = i; j <= 2*n; j++)
        {
            licz++;
            cur = 0;
            for (int k=i; k<=j; k++)
            {
                cur++;
                if (spojna[pol[k]][licz] == 0) dfs(pol[k], 2*n, licz, i, j, cur);
            }
            ile_ciek[cur]++;
        }
    }
    for (int i = 1; i <=q; i++)
    {
        cout << ile_ciek[i] << " ";
    }

    return 0;
}