RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03745

Infinite Race

설명

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.

(An illustrative figure from the official statement is omitted here.)

제약
  • \(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\).

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

Group | Score | Limits 1 | 29 | \(N = 2\) 2 | 34 | \(x_{i} > 0\) for all \(i\) (that is, Anika only overtakes) 3 | 22 | \(N,Q\leq 100\) 4 | 15 | No additional constraints

입력 형식

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.

서브태스크
서브태스크점수설명

Subtask 1

29점

None

Subtask 2

34점

None

Subtask 3

22점

None

Subtask 4

15점

None

예제 1
입력
4
5
-2
2
1
-3
2
출력
1
예제 2
입력
2
4
1
1
1
1
출력
3
예제 3
입력
2
5
1
-1
1
-1
-1
출력
0
예제 4
입력
200000
7
199999
199999
1
199999
55
199999
55
출력
3
예제 5
입력
3
6
1
2
2
2
1
1
출력
3
문제 정보

rip 작성

출처 EGOI 2024

평가 및 의견

Infinite Race

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Infinite Race

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8