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
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
int n,k;
int tab[2][100001];
int poz[200000][2];
int cie[100001];
int main(){
    std::cin>>n>>k;
    std::ios_base::sync_with_stdio(0);
    for(int j=0;j<2;j++)
        for(int i=0;i<n;i++){
            std::cin>>tab[j][i];
            poz[tab[j][i]][0]=j;
            poz[tab[j][i]][1]=i;
        }

    for(int i=1;i<=2*n;i++) {
        int result=0;
        int kro=0;
        for (int j = i; j <= 2*n; j++){
            int z=poz[j][0];
            int ko=poz[j][1];
            auto c=[&](int x){return (x<j && x>=i);};
            int a1=c(tab[z][ko!=0?ko-1:n-1]);
            int a2=c(tab[z][ko!=n-1?ko+1:0]);
            //std::cout<<"xx "<<a2<<" "<< z<<" "<<(ko!=n-1?ko+1:0)<<std::endl;
            int a3=c(tab[!z][ko]);
            int p1=c(tab[!z][ko!=0?ko-1:n-1]);
            int p2=c(tab[!z][ko!=n-1?ko+1:0]);
            int count=a1+a2+a3;
            if(count==0)
                result++;
            if(a1&&a2&&a3&&!p1&&!p2)
                result-=2;
            else
            if((a1&&a3&&!p1)||(a2&&a3&&!p2)||(a1&&a2&&(!p1||!p2||!a3)))
                result--;
            if(a1&&!(a3&&p1))
                kro++;
            if(a2&&!(a3&&p2))
                kro++;
            if(kro==n){
                kro++;
                //std::cout<<"zam"<<std::endl;
                result++;
            }
            //std::cout<<i<<" "<<j<<" "<<result<<std::endl;
            cie[result]++;
        }

    }
    for(int i=1;i<=k;i++)
        std::cout<<cie[i]<<" ";
    std::cout<<"\n";

}