#P9910. [COCI 2023/2024 #2] Dizalo
[COCI 2023/2024 #2] Dizalo
Problem Description
There are people in an elevator. The -th person gets off at floor , and forms a permutation.
The elevator is long and narrow, so initially the people stand in a single line inside the elevator in order of their indices. The elevator goes upward and passes floors 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 operations. In each operation, a given means removing the person with index . You need to output the answer before the first operation and after each operation.
Input Format
The first line contains two integers .
The second line contains numbers , guaranteed to form a permutation of .
The third line contains numbers , representing the queries.
Output Format
Output one line with 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
| Score | Special property | |
|---|---|---|
| None |
For all testdata, .
Translated by ChatGPT 5