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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#include <bits/stdc++.h>

using namespace std;

int n, k;
vector<int> rows[2];
vector<pair<int, int>> pos;
vector<unsigned long long> res(11);

bool neigh(pair<int, int> l, pair<int, int> r) {
    if (l.second == r.second) return true;
    int col1 = l.second + 1;
    if (col1 >= n) col1 -= n;
    int col2 = l.second - 1;
    if (!l.second) col2 += n;
    if (r.second == col1 || r.second == col2) {
        return l.first == r.first;
    }
    return false;
}

void solven100() {
    for (int l = 1; l <= 2 * n; l++) {
        for (int r = l; r <= 2 * n; r++) {
            vector<bool> seen(2 * n, false);
            int count = 0;
            vector<pair<int, int>> q;
            for (int row = 0; row < 2; row++) 
            for (int col = 0; col < n; col++) {
                if (l <= rows[row][col] && r >= rows[row][col]) {
                    if (seen[n * row + col]) continue;
                    seen[n * row + col] = true;
                    if (++count > 10) break;
                    q.push_back({row, col});
                    while (q.size()) {
                        auto p = q.back(); q.pop_back();
                        int row = p.first, col = p.second;
                        {int nrow = 1 - row;
                        int ncol = col;
                        if (l <= rows[nrow][ncol] && r >= rows[nrow][ncol] && !seen[n * nrow + ncol]) {
                            seen[n * nrow + ncol] = true;
                            q.push_back({nrow, ncol});
                        }}
                        {int nrow = row;
                        int ncol = col + 1; if (ncol == n) ncol -= n;
                        if (l <= rows[nrow][ncol] && r >= rows[nrow][ncol] && !seen[n * nrow + ncol]) {
                            seen[n * nrow + ncol] = true;
                            q.push_back({nrow, ncol});
                        }}
                        {int nrow = row;
                        int ncol = col ? col - 1 : n - 1;
                        if (l <= rows[nrow][ncol] && r >= rows[nrow][ncol] && !seen[n * nrow + ncol]) {
                            seen[n * nrow + ncol] = true;
                            q.push_back({nrow, ncol});
                        }}
                    }
                }
            }
            res[count]++;
        }
    }
    for (int i = 1; i <= k; i++) cout << res[i] << ' ';
    cout << endl;
}

void solve() {
    cin >> n >> k;
    rows[0] = vector<int>(n);
    rows[1] = vector<int>(n);
    pos = vector<pair<int, int>>(2 * n);
    for (int i = 0; i < n; i++) {
        cin >> rows[0][i];
        pos[rows[0][i] - 1] = {0, i};
    }
    for (int i = 0; i < n; i++) {
        cin >> rows[1][i];
        pos[rows[1][i] - 1] = {1, i};
    }

    if (n <= 100) {
        solven100();
        return;
    } 
    solven100();

    // if (k == 1) {
        // solvek1();
        // return;
    // }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

// #ifdef LOCAL
//     int t; cin >> t; while (t--)
// #endif

    solve();

    cout.flush();
}