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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// clang-format off
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()

template<class C> void mini(C &a5, C b5) { a5 = min(a5, b5); }
template<class C> void maxi(C &a5, C b5) { a5 = max(a5, b5); }

#ifdef LOCAL
const bool debug = true;
#else
const bool debug = false;
#define cerr if (true) {} else cout
#endif
// clang-format on

#define int long long
#define double long double

const int INF = 1e18;
const int mod = 1e9 + 7;
const int nax = 1e6 + 100;
const int kax = 11;

int arr[nax][2];
int n, k;

const int base = 1 << 18;
int tree[4*base][kax];
int tree_change[2*base];

void update_tree(int where) {
	int change = tree_change[where];
	assert(change>=0);
	for (int i = 0; i < min(change, kax); i++)
		tree[where][i] = 0;
	for (int i = 0; i+change < kax; i++)
		tree[where][i+change] = tree[where*2][i] + tree[where*2+1][i];
}

void add(int c, int q_begin, int q_end, int begin=0, int end=base, int where=1) {
	if (q_begin <= begin && end <= q_end) {
		tree_change[where] += c;
		update_tree(where);
		return;
	}
	if (q_end <= begin) return;
	if (end <= q_begin) return;
	
	int middle = (begin + end) / 2;
	add(c, q_begin, q_end, begin, middle, where*2);
	add(c, q_begin, q_end, middle, end, where*2+1);
	update_tree(where);
}

void add_bottom(int where) {
	where *= 2;
	where += 2*base;
	tree[where][0] = 1;
	while (where) {
		where /= 2;
		update_tree(where);
	}
}

/*void init_tree() {
	for (int i = 1; i <= 2*n; i++) {
		tree[2*base+i][0] = 1;
	}
	for (int i = 2*base-1; i > 0; i--) {
		update_tree(i);
	}
}*/

void debug_tree(int end) {
	if (!debug) return;
	
	cerr << "tree:\n";
	for (int i = 0; i < end; i++) {
		int res = 0;
		int where = base + i;
		while (where) {
			res += tree_change[where];
			where /= 2;
		}
		cerr << res << " ";
	}
	cerr << "\n";
	for (int i = 0; i < kax; i++) {
		cerr << tree[1][i] << " ";
	}
	cerr << "\n";
}

void read_input() {
	cin >> n >> k;
    for (int j = 0; j < 2; j++)
		for (int i = 0; i < n; i++) {
			cin >> arr[i][j];
		}
	
	arr[n][0] = arr[0][0];
	arr[n][1] = arr[0][1];
}

struct My {
	pair<int, int> begin;
	pair<int, int> end;
	
	My(pair<int, int> inner, pair<int, int> outer) {
		begin = {outer.first, inner.first};
		end = {inner.second, outer.second};
	}
};

My single_segment(int in1, int in2, int out1, int out2) {
	if (in1 > in2) swap(in1, in2);
	if (out1 > out2) swap(out1, out2);
	
	if (out1 < in1 && in2 < out2) {
		return {{in1, in2}, {out1+1, out2-1}};
	}
	if (out2 < in1) {
		return {{in1, in2}, {out2+1, 2*n}};
	}
	if (in2 < out1) {
		return {{in1, in2}, {1, out1-1}};
	}
	return {{-1, -1}, {-1, -1}};
}

vector<My> get_segments() {
	vector<My> res, res2;
	for (int i = 0; i < n; i++) {
		res.push_back(single_segment(arr[i][0], arr[i][0], arr[i][1], arr[i+1][0]));
		res.push_back(single_segment(arr[i][1], arr[i][1], arr[i][0], arr[i+1][1]));
		res.push_back(single_segment(arr[i][0], arr[i][1], arr[i+1][0], arr[i+1][1]));
	}
	for (const My &m : res)
		if (m.begin.first != -1)
			res2.push_back(m);
	return res2;
}

struct Update {
	pair<int, int> seg;
	int when;
	int how;
	
	void perform() const {
		add(how, seg.first, seg.second+1);
	}
	
	bool operator < (const Update &other) const {
		return when < other.when;
	}
};

int res[kax];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cerr << base << endl;
    
    read_input();
    //init_tree();

    vector<Update> updates;
    for (const My &m : get_segments()) {
		cerr << m.begin.first << "," << m.begin.second << " " << m.end.first << "," << m.end.second << "\n";
		updates.push_back({m.begin, m.end.first, 1});
		updates.push_back({m.begin, m.end.second+1, -1});
	}
	sort(ALL(updates));
	
	int prev_when = 1;
	for (const Update &u : updates) {
		while (prev_when < u.when) {
			add_bottom(prev_when);
			cerr << prev_when << "\n";
			debug_tree(10);
			for (int i = 0; i < kax; i++) {
				res[i] += tree[1][i];
			}
			prev_when++;
		}
		u.perform();
		//prev_when = u.when;
		//cerr << u.seg.first << " " << u.seg.second << "   " << u.how << " " << u.when << "\n";
		//debug_tree(10);
		//cerr << "\n";
	}
	
	res[1] += res[0];
	for (int i = 1; i <= k; i++) {
		cout << res[i] << " ";
	}
    
    return 0;
}/*
2 10
1 2
3 4

2 10
1 4
3 2


3 10
1 5 3
4 2 6

5 10
1 3 5 7 9
2 6 4 8 10
*/