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

32107번 - Infinite Race 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB95562.500%

문제

Every year, there is a marathon in Eindhoven. This year, the organizers have come up with something special, and instead of being over after 42 kilometres, the race goes on forever! To keep the organization simple, the race takes place on a running track at Eindhoven university, and the participants run an infinite number of laps on the track.

Anika is excited to be one of the $N$ participants, numbered from 0ドル$ to $N-1$. She was quick to sign up which means she is participant 0ドル$. She starts right after the finish line with all other participants positioned ahead of her on the track. Anika cannot keep track of how many laps she has run, but she remembers when she overtakes someone or when someone overtakes her. What is the minimum number of times she must have crossed the finish line? Nobody moves backwards, and no overtaking happens exactly at the finish line. Furthermore, note that the participants do not necessarily run at a constant speed.

입력

The first line of input contains an integer $N,ドル the number of participants.

The second line contains an integer $Q,ドル the number of events.

The following $Q$ lines describe the events in the order they occurred during the race. The $i$th line contains an integer $x_i$.

  • If $x_i > 0,ドル it means that Anika overtook participant $x_i$.
  • If $x_i < 0,ドル it means that participant $-x_i$ overtook Anika.

출력

Output a single integer, the minimum number of times Anika must have crossed the finish line.

제한

  • 2ドル \le N \le 200,000円$.
  • 1ドル \le Q \le 200,000円$.
  • 1ドル \le x_i \le N-1$ or $-(N-1) \le x_i \le -1$.

서브태스크

번호배점제한
129

$N = 2$

234

$x_{i} > 0$ for all $i$ (that is, Anika only overtakes)

322

$N,Q\leq 100$

415

No additional constraints

예제 입력 1

4
5
-2
2
1
-3
2

예제 출력 1

1

예제 입력 2

2
4
1
1
1
1

예제 출력 2

3

예제 입력 3

2
5
1
-1
1
-1
-1

예제 출력 3

0

예제 입력 4

200000
7
199999
199999
1
199999
55
199999
55

예제 출력 4

3

예제 입력 5

3
6
1
2
2
2
1
1

예제 출력 5

3

노트

Note that some of the samples are not valid input for all test groups.

In the first sample, there are $N = 4$ participants and $Q = 5$ events. Anika first gets overtaken by 2ドル,ドル who is now a full lap ahead of her. Then she overtakes 2ドル$ back, followed by overtaking 1ドル$ and then being overtaken by 3ドル$. At this point, Anika can still be on her first lap. Finally, she overtakes 2ドル$ again, and to do so means that she must have crossed the finish line at least once.

In the second sample, there is just one participant other than Anika. Anika overtakes the other participant four times, meaning that Anika must have crossed the finish line at least three times.

출처

Olympiad > European Girls' Olympiad in Informatics > EGOI 2024 > Day 1 A번

채점 및 기타 정보

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

출처

대학교 대회

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

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