题目描述
Problem Description
$n$ people are taking an elevator, where the $i$-th person gets off at the $a_i$-th floor, and $a_{1\sim n}$ forms a permutation.
The elevator is rectangular, so the $n$ people initially line up in the elevator in numerical order. The elevator will pass through floors $1$ to $n$ in ascending order.
When a person needs to get off the elevator, everyone in front of them must also temporarily get off, and they can then return to the elevator in any order. Those behind do not need to and will not get off.
If the people who temporarily get off always return to the elevator using the optimal strategy, please determine the minimum total number of times everyone gets off the elevator.
Given $q$ operations, each specifying $x_i$ to remove the person with the number $x_i$, you need to calculate the answer before the first operation and after each operation.
Input Format
The first line contains two integers $n$ and $q$.
The second line contains $n$ numbers $a_{1\sim n}$, which form a permutation of $1$ to $n$.
The third line contains $q$ numbers $x_{1\sim q}$, representing the $q$ queries.
Output Format
Output one line with $q+1$ numbers, representing the answer before the first operation and after each operation.
Sample Input and Output
Input Sample #1
5 2
3 4 1 2 5
3 2
Output Sample #1
9 6 4
Input Sample #2
7 0
4 5 2 1 6 3 7
Output Sample #2
13
Input Sample #3
3 2
3 1 2
1 2
Output Sample #3
5 2 1
Notes
Data Range
| Subtask | Points | Special Conditions |
|---|---|---|
| 1 | 16 | $n, q \le 100$ |
| 2 | 19 | $n, q \le 1000$ |
| 3 | 29 | $q = 0$ |
| 4 | 46 | None |
For all data, $0 \le q < n \le 10^5$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分