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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   vi         = vector<int>;
using   pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

constexpr int INF = 1e9;
constexpr int MAX_K = 11;

void combine(array<int, MAX_K>& dst, const array<int, MAX_K>& src, int offset) {
	rep(i, offset, MAX_K) {
		dst[i] += src[i-offset];
	}
}

struct SegTree {
	vi add, least;
	vector<array<int, MAX_K>> cnt;
	int len;

	SegTree(int n) {
		for (len = 1; len < n; len *= 2);
		add.resize(len, 0);
		add.resize(len*2, INF);
		least.resize(len*2, INF);
		cnt.resize(len*2, {});
		rep(i, 0, len) cnt[len+i][0] = 1;
		for (int i = len-1; i > 0; i--) {
			cnt[i][0] = cnt[i*2][0] * 2;
		}
	}

	array<int, MAX_K> get() const {
		array<int, MAX_K> ret = {};
		combine(ret, cnt[1], least[1]);
		return ret;
	}

	void update(int vb, int ve, int val, int i = 1, int b = 0, int e = -1) {
		if (e < 0) e = len;
		if (b >= ve || vb >= e) return;
		if (b >= vb && e <= ve) {
			add[i] += val;
			least[i] += val;
			return;
		}

		int m = (b+e) / 2;
		update(vb, ve, val, i*2, b, m);
		update(vb, ve, val, i*2+1, m, e);

		least[i] = min(least[i*2], least[i*2+1]);
		cnt[i] = {};
		combine(cnt[i], cnt[i*2], least[i*2]-least[i]);
		combine(cnt[i], cnt[i*2+1], least[i*2+1]-least[i]);
		least[i] += add[i];
	}
};

struct Event {
	int b, e, val;
};

vector<vector<Event>> events;

void solve(int mx, int k) {
	SegTree tree(mx);
	vector<ll> ans(k);
	for (int b = mx-1; b >= 0; b--) {
		tree.update(b, b+1, -INF);
		each(e, events[b]) {
			tree.update(e.b, e.e, e.val);
		}
		auto tmp = tree.get();
		rep(i, 1, k+1) ans[i-1] += tmp[i];
		ans[0] += tmp[0];
	}
	each(a, ans) cout << a << ' ';
	cout << '\n';
}

void add(int in, vi out, int val, int mx) {
	int b1 = 0, e2 = mx;
	each(v, out) {
		if (v < in) b1 = max(b1, v+1);
		else if (v > in) e2 = min(e2, v);
		else assert(0);
	}
	if (b1 > 0) events[b1-1].pb({in, e2, -val});
	events[in].pb({in, e2, val});
}

void run() {
	int n, k;
	cin >> n >> k;

	vi T[2];
	rep(i, 0, 2) {
		T[i].resize(n);
		each(v, T[i]) cin >> v, v--;
	}

	events.resize(n*2);

	rep(j, 0, n) {
		int a = T[0][j], b = T[0][(j+1)%n];
		int c = T[1][j], d = T[1][(j+1)%n];
		add(b, {a,c}, 1, n*2);
		add(b, {a,d}, 1, n*2);
		add(b, {a,c,d}, -1, n*2);
		add(d, {b,c}, 1, n*2);
	}

	solve(n*2, k);
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(10);
	run();
	cout << flush; _Exit(0);
}