## DMOPC '19 Contest 7 P5 - Soriya's Programming Project

View as PDF

Points: 20 (partial)
Time limit: 3.0s
Memory limit: 128M

Author:
Problem types

For her current programming project, Soriya needs to first construct the array which has length . However, to entertain herself, she decides to add the elements in the order described by the permutation . That is, for her th insertion, she will add the element to its position in the array. Since Soriya has nothing better to do with her life, she wonders: how many inversions will the array have after each insertion? An inversion is a pair of indices such that and .

#### Input Specification

The first line contains the positive integer .
The second line consists of positive integers, the array .
The third line consists of positive integers, the permutation .

#### Output Specification

Output lines, the th of which containing a single integer, the number of inversions after Soriya adds her th element.

for

#### Sample Input 1

5
4 3 1 2 3
1 2 3 4 5

#### Sample Output 1

0
1
3
5
6

#### Sample Input 2

5
4 3 1 2 3
3 5 1 4 2

#### Sample Output 2

0
0
2
3
6