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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#pragma GCC optimize("O3")
/* #pragma GCC target("sse4") */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ssize(x) int(x.size())
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
// #define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define FORE(i, l, r) for(int i = (l); i <= (r); ++i)
// # define REP(i, n) FOR(i, 0, (n) - 1)
# define REP(i, n) FORE(i, 0, (n) - 1)
#define FORR(x,arr) for(auto &x: arr)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
/* #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "),...); }(x), cerr << '\n' */
#define debug(x...) ;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
using namespace std;
using namespace __gnu_pbds;

#ifdef ONLINE_JUDGE
#define debug(...) {}
#endif
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) { return o << '(' << p.first << ", " << p.second << ')'; }
template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) { o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}'; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// 1 << 19 if segtree where merges matter.
/* #define N 1000001 */
#define N 200008

// Easiest Potyczki Day 4 B ever.
// kmina w 0.5h, impl same. // 45mins impl with bugfixes jednak bcs I just couldnt do comb() b4 xd.
// Diff to SKRZYŻOWANIA XDDD. (F Arek)
// Or Kino kombi clutch on Malowanie Płotu

int t[N << 2][11];
int cnt[N << 2][11];
int lazy[N << 2];

/* void build(int v, int tl, int tr, int arr[]){ */
/*     if(tl == tr){ */
/*         t[v] = arr[tl]; */
/*         cnt[v] = 1; */
/*         return; */
/*     } */
/*     lazy[v] = 0; */
/*     int tm = (tl+tr)>>1; */
/*     build(v<<1,tl,tm,arr); */
/*     build(v<<1|1,tm+1,tr,arr); */
/*     t[v] = min(t[v<<1] , t[v<<1|1]); */
/*     cnt[v] = 0; */
/*     if(t[v] == t[v<<1]) */
/*         cnt[v] += cnt[v<<1]; */
/*     if(t[v] == t[v<<1|1]) */
/*         cnt[v] += cnt[v<<1|1]; */
/* } */

// after 3 bugs, prob like time to do this:
array<pair<int,int>, 11> comb(array<pair<int,int>, 11> f, array<pair<int,int>, 11> s){
    array<pair<int,int>,11> res{};
    array<pair<int,int>,11> sth[2] {f, s};
    debug(f, s);
    {
        int it1 = 0, it2 = 0;
        REP(i,11){
            if(it1 == 11 || !sth[0][it1].e2){
                if(it2 == 11 || !sth[0|1][it2].e2)
                    break;
                res[i].e1 = sth[0|1][it2++].e1; // bug1 z i++.
            }
            else if(it2 == 11 || !sth[0|1][it2].e2){
                res[i].e1 = sth[0][it1++].e1;
            }
            else{
                if(sth[0][it1].e1 < sth[0|1][it2].e1){
                    res[i].e1 = sth[0][it1++].e1;
                }
                else{
                    if(sth[0][it1].e1 == sth[0|1][it2].e1){
                        res[i].e1 = sth[0|1][it2++].e1;
                        ++it1;
                    }
                    else{
                        res[i].e1 = sth[0|1][it2++].e1;
                    }
                }
            }
        }
        debug(it1, it2);
        int cr = 0;
        REP(_,2){
            int it = 0; // bug2
            REP(i,11){
                if(!sth[cr][i].e2)
                    break;
                // bug3 -- nc kopiowanie 3 razy hyperbugged kodu, instead of saving mental energy to spot bugs
                while(it < 11 && res[it].e1 < sth[cr][i].e1)
                    ++it;
                if(it == 11)
                    break;
                /* assert(it < 11 && res[it].e2); */
                if(res[it].e1 == sth[cr][i].e1){
                    res[it++].e2 += sth[cr][i].e2;
                }
            }
            cr |= 1;
        }
    }
    debug(res);
    return res;
}

void build(int v, int tl, int tr){
    if(tl == tr){
        cnt[v][0] = 1;
        return;
    }
    int tm = (tl+tr)>>1;
    build(v<<1,tl,tm);
    build(v<<1|1,tm+1,tr);
{
    array<pair<int,int>,11> rl;
    REP(i,11)
        rl[i] = {t[v<<1][i], cnt[v<<1][i]};
    array<pair<int,int>,11> rr;
    REP(i,11)
        rr[i] = {t[v<<1|1][i], cnt[v<<1|1][i]};
    /* array<pair<int,int>,11> res = comb(move(rl), move(rr)); */
    array<pair<int,int>,11> res = comb(rl, rr);
    REP(i,11){
        t[v][i] = res[i].e1;
        cnt[v][i] = res[i].e2;
    }
}
    // elegant merge.  (or not so elegant w sumie xd)
    // haven't done one since 2019 or 2020.
    /* { */
    /*     int it1 = 0, it2 = 0; */
    /*     memset(&cnt[v],0,11 << 2); */
    /*     REP(i,11){ */
    /*         if(it1 == 11 || !cnt[v<<1][it1]){ */
    /*             if(it2 == 11 || !cnt[v<<1|1][it2]) */
    /*                 break; */
    /*             // 'i' xd. */
    /*             t[v][i] = t[v<<1|1][it2++]; */
    /*         } */
    /*         else if(it2 == 11 || !cnt[v<<1|1][it2]){ */
    /*             t[v][i] = t[v<<1][it1++]; */
    /*         } */
    /*         else{ */
    /*             if(t[v<<1][it1] < t[v<<1|1][it2]){ */
    /*                 t[v][i] = t[v<<1][it1++]; */
    /*             } */
    /*             else{ */
    /*                 t[v][i] = t[v<<1|1][it2++]; */
    /*             } */
    /*         } */
    /*     } */
    /*     int cr = v << 1; */
    /*     REP(_,2){ */
    /*     int it = 0; */
    /*         REP(i,11){ */
    /*             if(!cnt[cr][i]) */
    /*                 break; */
    /*             // bug3 -- nc kopiowanie 3 razy hyperbugged kodu, instead of saving mental energy to spot bugs */
    /*             while(it < 11 && t[v][it] < t[cr][i]) */
    /*                 ++it; */
    /*             if(it == 11) */
    /*                 break; */
    /*             assert(cnt[v][it]); */
    /*             if(t[v][it] == t[cr][i]){ */
    /*                 cnt[v][it++] += cnt[cr][i]; */
    /*             } */
    /*         } */
    /*         cr |= 1; */
    /*     } */
    /* } */
}

void push(int v){
    if(lazy[v]){
        lazy[v<<1] += lazy[v];
        lazy[v<<1|1] += lazy[v];
        REP(i,11){
            if(cnt[v<<1][i])
                t[v<<1][i] += lazy[v];
            if(cnt[v<<1|1][i])
                t[v<<1|1][i] += lazy[v];
        }
        lazy[v] = 0;
    }
}

void modify(int v, int tl, int tr, int l, int r, int inc){
    if(l > r) return;
    if(tl == l && tr == r){
        lazy[v] += inc;
        REP(i,11)
            if(cnt[v][i])
                t[v][i] += inc;
        return;
    }
    push(v);
    int tm = (tl+tr)>>1;
    modify(v<<1,tl,tm,l,min(tm,r),inc);
    modify(v<<1|1,tm+1,tr,max(l,tm+1),r,inc);
{
    array<pair<int,int>,11> rl;
    REP(i,11)
        rl[i] = {t[v<<1][i], cnt[v<<1][i]};
    array<pair<int,int>,11> rr;
    REP(i,11)
        rr[i] = {t[v<<1|1][i], cnt[v<<1|1][i]};
    /* array<pair<int,int>,11> res = comb(move(rl), move(rr)); */
    array<pair<int,int>,11> res = comb(rl, rr);
    REP(i,11){
        t[v][i] = res[i].e1;
        cnt[v][i] = res[i].e2;
    }
}
    /* { */
    /*     int it1 = 0, it2 = 0; */
    /*     memset(&cnt[v],0,11 << 2); */
    /*     REP(i,11){ */
    /*         if(it1 == 11 || !cnt[v<<1][it1]){ */
    /*             if(it2 == 11 || !cnt[v<<1|1][it2]) */
    /*                 break; */
    /*             t[v][i] = t[v<<1|1][it2++]; */
    /*         } */
    /*         else if(it2 == 11 || !cnt[v<<1|1][it2]){ */
    /*             t[v][i] = t[v<<1][it1++]; */
    /*         } */
    /*         else{ */
    /*             if(t[v<<1][it1] < t[v<<1|1][it2]){ */
    /*                 t[v][i] = t[v<<1][it1++]; */
    /*             } */
    /*             else{ */
    /*                 t[v][i] = t[v<<1|1][it2++]; */
    /*             } */
    /*         } */
    /*     } */
    /*     int cr = v << 1; */
    /*     REP(_,2){ */
    /*     int it = 0; */
    /*         REP(i,11){ */
    /*             if(!cnt[cr][i]) */
    /*                 break; */
    /*             // bug3 -- nc kopiowanie 3 razy hyperbugged kodu, instead of saving mental energy to spot bugs */
    /*             while(it < 11 && t[v][it] < t[cr][i]) */
    /*                 ++it; */
    /*             if(it == 11) */
    /*                 break; */
    /*             assert(it < 11 && cnt[v][it]); */
    /*             if(t[v][it] == t[cr][i]){ */
    /*                 cnt[v][it++] += cnt[cr][i]; */
    /*             } */
    /*         } */
    /*         cr |= 1; */
    /*     } */
    /* } */
}

array<pair<int,int>,11> _empty;

// {min, mincnt}
array<pair<int,int>,11> query(int v, int tl, int tr, int l, int r){
    if(l > r) return _empty;
    // XDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
    // spotted pol tygodnia po conteście.
    // ma sens tle tera......
    // rip 97 codejam place.
    /* if(tl == l && tr == r && tr == tl){ */
    if(tl == l && tr == r){
        /* return {t[v],cnt[v]}; */
        array<pair<int,int>,11> cr;
        REP(i,11)
            cr[i] = {t[v][i], cnt[v][i]};
        return cr;
    }
    push(v);
    int tm = (tl+tr)>>1;
    auto rl = query(v<<1,tl,tm,l,min(tm,r));;
    auto rr = query(v<<1|1,tm+1,tr,max(l,tm+1),r);
    /* auto sth = {rl, rr}; */
    /* array<pair<int,int>,11> sth[2] = {rl, rr}; */
    array<pair<int,int>,11> res = comb(rl, rr);
    /* // MEGA RIP STRUCT AND COMB() */
    /* { */
    /*     int it1 = 0, it2 = 0; */
    /*     REP(i,11){ */
    /*         if(it1 == 11 || !sth[0][it1].e2){ */
    /*             if(it2 == 11 || !sth[0|1][it2].e2) */
    /*                 break; */
    /*             res[i].e1 = sth[0|1][it2++].e1; // bug1 z i++. */
    /*         } */
    /*         else if(it2 == 11 || !sth[0|1][it2].e2){ */
    /*             res[i].e1 = sth[0][it1++].e1; */
    /*         } */
    /*         else{ */
    /*             if(sth[0][it1].e1 < sth[0|1][it2].e1){ */
    /*                 res[i].e1 = sth[0][it1++].e1; */
    /*             } */
    /*             else{ */
    /*                 res[i].e1 = sth[0|1][it2++].e1; */
    /*             } */
    /*         } */
    /*     } */
    /*     debug(it1, it2); */
    /*     int cr = 0; */
    /*     REP(_,2){ */
    /*         int it = 0; // bug2 */
    /*         REP(i,11){ */
    /*             if(!sth[cr][i].e2) */
    /*                 break; */
    /*             // bug3 -- nc kopiowanie 3 razy hyperbugged kodu, instead of saving mental energy to spot bugs */
    /*             while(it < 11 && res[it].e1 < sth[cr][i].e1) */
    /*                 ++it; */
    /*             if(it == 11) */
    /*                 break; */
    /*             assert(it < 11 && res[it].e2); */
    /*             if(res[it].e1 == sth[cr][i].e1){ */
    /*                 res[it++].e2 += sth[cr][i].e2; */
    /*             } */
    /*         } */
    /*         cr |= 1; */
    /*     } */
    /* } */
    /* debug(rl, rr, res); */
    return res;
}

vector<pi> vec;
vector<pi> vecneg;
ll res[11];
vector<pi> stuff[200000]; //[l] -> {suffrom, inc/dec (val)}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, k;
    sc(n, k);
    int a[2][n];
    GET(a[0]);
    GET(a[1]);
    REP(i,2)
        FORR(x,a[i])
            --x;
    auto mn_empl = [&](int f, int s){
        if(f > s)
            swap(f,s);
        /* vec.emplace_back(f, s); */
        stuff[f].emplace_back(s, 1);
    };
    auto mn_empl_ng = [&](int f, int s){
        if(f > s)
            swap(f,s);
        /* vecneg.emplace_back(f, s); */
        stuff[f].emplace_back(s, -1);
    };
    REP(i,2){
        FOR(x,0,n){
            /* vec.emplace_back(a[i][x], a[i][x]); */
            mn_empl(a[i][x], a[i][x]);
            /* mn_empl(a[i][x], a[i][(x + 1) % n]); */
            mn_empl_ng(a[i][x], a[i][(x + 1) % n]);
        }
    }
    FOR(x,0,n){
        vi wh;
        wh.push_back(a[0][x]);
        wh.push_back(a[1][x]);
        wh.push_back(a[0][(x+1)%n]);
        wh.push_back(a[1][(x+1)%n]);
        /* mn_empl_ng(*min_element(all(wh)), *max_element(all(wh))); */
        mn_empl(*min_element(all(wh)), *max_element(all(wh)));
        mn_empl_ng(a[0][x], a[1][x]);
    }
    /* FOR(l,0,2*n){ */
    /*     FOR(r,l,2*n){ */
    /*         int cr = 0; */
    /*         FORR(x,vec) */
    /*             cr += x.e1 >= l && x.e2 <= r; */
    /*         FORR(x,vecneg) */
    /*             cr -= x.e1 >= l && x.e2 <= r; */
    /*         assert(cr >= 0); */
    /*         /1* debug(l,r,cr); *1/ */
    /*         if(cr <= 10) */
    /*             ++res[cr]; */
    /*     } */
    /* } */
    build(1,0,2*n-1);
    for(int l = 2 * n - 1; l >= 0; --l){
        /* modify(1,0,2*n-1,l,2*n-1,1); */
        for(auto &[suffrom, val]: stuff[l]){
            modify(1,0,2*n-1,suffrom,2*n-1,val);
        }
        auto crres = query(1,0,2*n-1,l,2*n-1);
        FORR(i,crres){
            if(!i.e2)
                break;
            if(i.e1 > 10)
                break;
            res[i.e1] += i.e2;
        }
    }
    res[1] += res[0];
    FORE(i,1,k)
        cout << res[i] << ' ';
    cout << '\n';
}