PivotOJ

Cow Checkups

시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 January BronzeBOJ 33509

문제

Note: We suggest using a language other than Python to earn full credit on this problem.

Farmer John's NN (1N75001 \leq N \leq 7500) cows are standing in a line, with cow 11 at the front of the line and cow NN at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from 11 to NN. The ii'th cow from the front of the line is of species aia_i (1aiN1 \leq a_i \leq N).

FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the ii'th cow in the line, only if it is of species bib_i (1biN1 \leq b_i \leq N).

FJ is lazy and does not want to completely reorder his cows. He will perform the following operation exactly once.

  • Select two integers ll and rr such that 1lrN1 \leq l \le r \leq N. Reverse the order of the cows that are between the ll-th cow and the rr-th cow in the line, inclusive.

FJ wants to measure how effective this approach is. For each c=0Nc=0 \ldots N, help FJ find the number of distinct operations (l,rl,r) that result in exactly cc cows being checked. Two operations (l1,r1l_1,r_1) and (l2,r2l_2,r_2) are different if l1l2l_1 \neq l_2 or r1r2r_1 \neq r_2.

입력

The first line contains an integer NN.

The second line contains a1,a2,,aNa_1, a_2, \ldots, a_N.

The third line contains b1,b2,,bNb_1, b_2, \ldots, b_N.

출력

Output N+1N+1 lines with the ii-th line containing the number of distinct operations (l,rl,r) that result in i1i-1 cows being checked.

예제

예제 1

입력
3
1 3 2
3 2 1
출력
3
3
0
0

예제 2

입력
3
1 2 3
1 2 3
출력
0
3
0
3

예제 3

입력
7
1 3 2 2 1 3 2
3 2 2 1 2 3 1
출력
0
6
14
6
2
0
0
0
코드를 제출하려면 로그인하세요.