#P9910. [COCI 2023/2024 #2] Dizalo

[COCI 2023/2024 #2] Dizalo

Problem Description

There are nn people in an elevator. The ii-th person gets off at floor aia_i, and a1na_{1\sim n} forms a permutation.

The elevator is long and narrow, so initially the nn people stand in a single line inside the elevator in order of their indices. The elevator goes upward and passes floors 1n1\sim n in increasing order.

When someone needs to get off the elevator, everyone in front of them must also get off temporarily, and then they may return to the elevator in any order. People behind them do not need to, and will not, get off the elevator.

If the people who temporarily get off always choose the best strategy to decide the order of returning to the elevator each time, find the minimum possible total number of times that all people get off the elevator.

You are given qq operations. In each operation, a given xix_i means removing the person with index xix_i. You need to output the answer before the first operation and after each operation.

Input Format

The first line contains two integers n,qn,q.

The second line contains nn numbers a1na_{1\sim n}, guaranteed to form a permutation of 1n1\sim n.

The third line contains qq numbers x1qx_{1\sim q}, representing the qq queries.

Output Format

Output one line with q+1q+1 numbers, representing the answer before the first operation and the answer after each operation.

5 2
3 4 1 2 5
3 2
9 6 4
7 0
4 5 2 1 6 3 7
13
3 2
3 1 2
1 2

5 2 1

Hint

Constraints

Subtask\text{Subtask} Score Special property
11 1616 n,q100n,q\le 100
22 1919 n,q1000n,q\le 1000
33 2929 q=0q=0
44 4646 None

For all testdata, 0q<n1050\le q< n\le 10^5.

Translated by ChatGPT 5