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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;
const int d = 10;

namespace SegT
{
	int n, mn[MAXN<<2], f[MAXN<<2][d+1], tag[MAXN<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	#define lson(u) ls(u),l,mid
	#define rson(u) rs(u),mid+1,r
	inline void push_up(int u)
	{
		int vl = ls(u), vr = rs(u);
		if(mn[vl] > mn[vr]) swap(vl, vr);
		mn[u] = mn[vl];
		for(int i=0; i<=d; ++i)
			f[u][i] = f[vl][i];
		for(int i=0,j=mn[vr]-mn[vl]; i<=d && j<=d; ++i, ++j)
			f[u][j] += f[vr][i];
	}
	inline void upd(int u,int k)
	{
		tag[u] += k; mn[u] += k;
	}
	inline void push_down(int u)
	{
		if(tag[u])
		{
			upd(ls(u), tag[u]); upd(rs(u), tag[u]);
			tag[u] = 0;
		}
	}
	void build(int u,int l,int r)
	{
		mn[u] = 0; f[u][0] = r-l+1; tag[u] = 0;
		if(l == r) return;
		int mid = (l+r)>>1;
		build(lson(u)); build(rson(u));
	}
	void update(int u,int l,int r,int ql,int qr,int k)
	{
		if(ql<=l && r<=qr){ upd(u,k); return;}
		push_down(u);
		int mid = (l+r)>>1;
		if(ql<=mid) update(lson(u),ql,qr,k);
		if(mid<qr) update(rson(u),ql,qr,k);
		push_up(u);
	}
}

int a[MAXN][2];

int main(void)
{
#ifdef He_Ren
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
#endif
	
	int n,dd;
	scanf("%d%d",&n,&dd);
	for(int j=0; j<=1; ++j)
		for(int i=1; i<=n; ++i)
			scanf("%d",&a[i][j]);
	
	vector< tuple<int,int,int> > seg; // {r, l, k}
	for(int i=1; i<=n; ++i)
	{
		for(int j=0; j<=1; ++j)
		{
			seg.emplace_back(a[i][j], a[i][j], 1);
			
			int x = a[i][j], y = a[i%n+1][j];
			seg.emplace_back(max(x,y), min(x,y), -1);
		}
		
		int x = a[i][0], y = a[i][1];
		seg.emplace_back(max(x,y), min(x,y), -1);
		
		x = min({a[i][0], a[i][1], a[i%n+1][0], a[i%n+1][1]});
		y = max({a[i][0], a[i][1], a[i%n+1][0], a[i%n+1][1]});
		seg.emplace_back(y, x, 1);
	}
	
	sort(seg.begin(), seg.end());
	
	static ll ans[d+1];
	
	SegT :: build(1,1,2*n);
	for(int i=1,j=0; i<=2*n; ++i)
	{
		while(j<(int)seg.size() && get<0>(seg[j]) <= i)
		{
			SegT :: update(1,1,2*n, 1, get<1>(seg[j]), get<2>(seg[j]));
			++j;
		}
		
		int cur = SegT :: mn[1], *val = SegT :: f[1];
		for(int x=0, y=cur; x<=d && y<=d; ++x, ++y)
			ans[y] += val[x];
		
		ans[0] -= 2*n-i;
	}
	
	ans[1] += ans[0];
	for(int i=1; i<=dd; ++i)
		printf("%lld ",ans[i]);
	return 0;
}