Logo
(追記) (追記ここまで)

30941번 - Dizalo 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB47549.091%

문제

In one city there is a tall skyscraper with $n$ floors. There are $n$ people waiting for an elevator on the ground floor. The $i$-th person wants to go to the floor $a_i$. There is no pair of people who want to go to the same floor.

The skyscraper has one elevator that is large enough for all people to fit in, but it is so narrow that two people cannot stand side by side; they must be one behind the other.

Everybody got in the elevator, but they had not thought about the order in which they have to exit it! Initially, the $i$-th person is at position $i,ドル looking from the elevator door. If a person wants to exit the elevator, everybody in front of them (closer to the door) must temporarily exit the elevator too. When returning back in the elevator, they can reorder themselves as they wish. People who are behind (further to the door) the person who wants to exit will not exit the elevator.

The illustration above shows the starting order of people in the elevator in the first example. The elevator is on floor 1ドル,ドル and the person in position 3ドル$ wants to exit. For them to exit, persons at positions 1ドル$ and 2ドル$ must exit too.

Mirko is viewing the situation they are in and contemplating. He wants to know how many exits from the elevator would there be be if the people returning to the elevator always returned optimally. If a person exits the elevator multiple times, each time is counted separately.

Mirko is an experienced coder, and he can solvee this problem quite easily. His happiness is short-lived, because next to him is his friend Slavko. Slavko came up with $q$ questions: If the person at position $x_i$ were not in the elevator, how many exits would there be then?

Mirko is interested in an answer before Slavko’s first question and after every question. Note that for each question, all the people from previous questions are also not considered to be in the elevator. Mirko started solving the problem but soon realized that even for him, this would not be quite easy. Help him solve this problem!

Note: The elevator will always move from the first floor to the $n$-th floor and stop at every floor on which someone wants to exit.

입력

The first line contains two non-negative integers $n$ and $q$ (0ドル ≤ q < n ≤ 10^5$), the number of people/floors and the number of questions.

The second line contains $n$ integers $a_i$ (1ドル ≤ a_i ≤ n,ドル $a_i \ne a_j$ for each $i \ne j$), where $a_i$ is the floor on which the $i$-th person wants to exit the elevator. The sequence $(a_i)$ is a permutation.

The third line contains $q$ integers $x_i$ (1ドル ≤ x_i ≤ n,ドル $x_i \ne x_j$ for each $i \ne j$), Slavko’s questions.

출력

In one line, print $q + 1$ numbers, where the $i$-th is the number of exists after $i - 1$ questions.

제한

서브태스크

번호배점제한
116

$n, q ≤ 100$

219

$n, q ≤ 1,円 000$

329

$q = 0$

446

No additional constraints.

예제 입력 1

5 2
3 4 1 2 5
3 2

예제 출력 1

9 6 4

예제 입력 2

7 0
4 5 2 1 6 3 7

예제 출력 2

13

예제 입력 3

3 2
3 1 2
1 2

예제 출력 3

5 2 1

힌트

Clarification of the first example:

The illustration shows the exits from the elevator before the first query.

The elevator is on the first floor, and the person at position 3ドル$ wants to exit. But, for them to exit, persons at positions 1ドル$ and 2ドル$ must exit first, and they return to the elevator at the same positions.

After that, on the second floor, the person at position 4ドル$ wants to exit. Again, persons at positions 1ドル$ and 2ドル$ must exit first, and they return to the elevator at the same positions.

After that, on the third floor, the person at position 1ドル$ exits the elevator, without anyone else having to exit the elevator.

After that, on the fourth floor, the person at position 2ドル$ exits the elevator, without anyone else having to exit the elevator.

And finally, on the fifth floor, the person at position 5ドル$ exits the elevator.

In total, there were 3ドル + 3 +たす 1 +たす 1 +たす 1 = 9$ exits from the elevator.

출처

Contest > Croatian Open Competition in Informatics > COCI 2023/2024 > Contest #2 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /