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
#include <bits/stdc++.h>
using namespace std;
int n,m;
array<long long,300001> f;
long long t;
long long d;
vector<int> a,b,s;
priority_queue<array<int,3>> p;
array<int,3> w;
long long k,i,j,x,y;
int main(){
	cin >> n >>  m;
	for(i=0;i<n;i++) {
		cin >> x;
		a.push_back(x);}
	for(i=0;i<m;i++){
		cin >> x;
		b.push_back(x);
	}
	f[2]+=n*m;
	//cout<< "AA\n";
	//return 0;
	for(i=0;i<n;i++) {
		s={};
		d=0;
		for(j=i+1;j<n;j++){
			if((a[j]-a[j-1])*d>0)
				t++;
			else if((a[j]-a[j-1])*d<0)
			{
				s.push_back(t);
				t=2;
				d=-d;
			}
			else{
				if(a[j]>a[i]) d=1;
				else d=-1;
				t=2;
			}
			p={};
			for(auto x:s) 
				p.push({x,x,1});
				
			p.push({t,t,1});
			y=2;
			for(k=1;k<=m && k<=j-i+1;k++)
			{	
				if(y==1) {
					f[2]+=m-k+1;
					continue;
				}
				w=p.top();
				p.pop();
				x=(w[1]+2*w[2])/(w[2]+1);
				p.push({x,w[1],w[2]+1});
				w=p.top();
				//cout << w[0] << ' ' << k << ' ' << i << ' ' << j << '\n';
				f[w[0]]+=m-k+1;
				if(w[0]==2)
					y=1;
			}
		}
	}
	//cout <<'\n';
	for(i=0;i<m;i++) {
		//break;
		s={};
		d=0;
		for(j=i+1;j<m;j++){
			if((b[j]-b[j-1])*d>0)
				t++;
			else if((b[j]-b[j-1])*d<0)
			{
				s.push_back(t);
				t=2;
				d=-d;
			}
			else{
				if(b[j]>b[i]) d=1;
				else d=-1;
				t=2;
			}
			p={};
			for(auto x:s) 
				p.push({x,x,1});
				
			p.push({t,t,1});
			y=2;
			for(k=1;k<=n && k<=j-i;k++)
			{	
				if(y==1) {
					f[2]+=n-k+1;
					continue;
				}
				w=p.top();
				p.pop();
				x=(w[1]+2*w[2])/(w[2]+1);
				p.push({x,w[1],w[2]+1});
				w=p.top();
				//cout << w[0] << ' ' << k << ' ' << i << ' ' << j << '\n';
				f[w[0]]+=n-k+1;
				if(w[0]==2)
					y=1;
			}
		}
	}
	for(i=1;i<=n+m;i++)
		cout << f[i] << ' ';
	cout << '\n';
}