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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, v) for(auto &x: v)
#define PB push_back
#define SZ(x) ((int)x.size())
#define X first
#define Y second

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;

ii d[3] = {{0, -1}, {0, 1}, {1, 0}};

ii operator+(const ii &a, const ii &b) {
    return {a.X + b.X, a.Y + b.Y};
}

struct UF {
    vi par;
    int comp;

    UF(int n) {
        par.resize(n);
        iota(par.begin(), par.end(), 0);
        comp = n;
    }

    int Find(int x) {
        return par[x] == x ? x : par[x] = Find(par[x]);
    }

    void Union(int v, int u) {
        v = Find(v), u = Find(u);
        if(v == u) return;
        par[v] = u;
        comp--;
    }
};

void solve() {
    int n, k;
    cin >> n >> k;
    vi vec[2] = {vi(n), vi(n)};
    vector<ii> pos(n * 2);
    vi ans(n * 2 + 1);
    FOR(i, 0, 2) TRAV(x, vec[i]) cin >> x;
    FOR(i, 0, 2) FOR(j, 0, n) pos[vec[i][j] - 1] = {i, j};
    FOR(l, 0, n * 2) {
        UF adam(n * 2);
        FOR(r, l, n * 2) {
            FOR(kk, 0, 3) {
                ii nowy = pos[r] + d[kk];
                nowy.X = (nowy.X + 2) % 2;
                nowy.Y = (nowy.Y + n) % n;
                int col = vec[nowy.X][nowy.Y] - 1;
                if(l <= col && col <= r) adam.Union(r, col);
            }
            ans[adam.comp - (n * 2 - (r - l + 1))]++;
        }
    }
    FOR(i, 1, k + 1) cout << ans[i] << " \n"[i == k];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int tt; cin >> tt;
    // FOR(te, 0, tt) {
    //     // cout << "Case #" << te + 1 << ": ";
    //     solve();
    // }
    solve();
    return 0;
}