| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 1024 MB | 25 | 14 | 9 | 64.286% |
Amida-kuji is a lottery popular in Japan, which can be used to assign $w$ prizes to $w$ people. The game consists of $w$ vertical lines, called legs, and some horizontal bars that connect adjacent legs. The tops of the legs are the starting positions of the $w$ people, and the prizes are at the bottom of the legs. To determine the prize of the $i$th person, one has to move down on the $i$th leg, starting at the top, and switch the leg whenever a horizontal bar is encountered. You can see such a game and how to trace a path in Figure J.1.
You want to manipulate the lottery in such a way that the $i$th person gets the $i$th prize, for every $i,ドル by removing some horizontal bars. Since you do not want to get caught, you want to remove as few bars as possible.
Figure J.1: Visualization of an Amida-kuji game. The first person is connected to the third prize. This is also Sample Input 2 after all connections are added and before any connection is removed. To connect the $i$th person to the $i$th prize, it suffices to remove both horizontal bars between legs 2ドル$ and 3ドル$ and the topmost horizontal bar between legs 3ドル$ and 4ドル$. This is the only minimal solution.
For this problem, the initial game configuration has no horizontal bars. Then, horizontal bars are added one by one or are removed again. After each change, you want to know the minimum number of horizontal bars that need to be removed such that the $i$th prize is assigned to the $i$th person for each $i$. Note that this is always possible by removing all horizontal bars.
The input consists of:
It is guaranteed that all horizontal bars have different heights at every moment.
After each change, output a single integer, the minimum number of horizontal bars that need to be removed in the game with the currently existing bars such that the $i$th prize is assigned to the $i$th person for each $i$.
4 6 7 1 1 2 2 3 4 4 3 4 5 1 2 6 3 4 3 2 3 6 3 4
1 2 1 0 1 2 1
5 9 12 1 3 4 2 1 2 3 2 3 4 4 5 5 2 1 6 4 3 7 2 3 8 4 3 9 4 5 6 4 3 7 2 3 1 3 4
1 2 3 4 3 2 3 4 3 4 3 2
ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2023 J번