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

Tjelesni

설명

The first semester at the university is coming to an end. Marin decided to attend
a PE class in order to collect his 12th attendance and thus pass the course. He
was surprised by the number of students waiting in front of the gym.
He counted \(n\) students (including himself) and noticed an interesting property:
no two students have the same height, and for every integer from 1 to \(n\) there is
exactly one student of that height.
Before the class started, the students lined up in a row. The heights of the students
in the row, observed from left to right, form a permutation \(p\) of size \(n\). The
professor has some unusual requirements for the order of students in the row, so
he decided to issue \(q\) commands that must be executed in the given order.
Each command is of the form \(l_{i}\) \(r_{i}\) and means that the students at positions from \(l_{i}\) to \(r_{i}\) (inclusive) need
to step out of the row, and then fill the empty positions in the following way: position \(l_{i}\) is filled by the
shortest student among those taken out. Position \(l_{i} + 1\) is filled by the tallest of the remaining students.
Position \(l_{i} + 2\) is again filled by the shortest of the remaining students, position \(l_{i} + 3\) by the tallest, and
so on, alternating between the shortest and the tallest until position \(r_{i}\) is filled.
After executing all the commands, Marin is no longer sure whether he is standing in the correct position
or if at some point he moved to the wrong place. However, he remembers the initial permutation \(p\), all \(q\)
commands in the order they were given, and he has told you his height \(m\). He asks you to determine the
position where he should be standing.

제약
입력 형식

The first line contains three natural numbers \(n\), \(q\) i \(m\) (\(1 \le n\), \(q \le 10^{5}\), \(1 \le m \le n\)), the numbers from the
problem statement.
The second line contains a sequence of \(n\) numbers \(1 \le p_{i} \le n\), the permutation \(p\).
Each of the next \(q\) lines contain two numbers \(1 \le l_{i} \le r_{i} \le n\), the \(i\)-th command.

출력 형식

In the first and only line output one number - the position Marin should occupy.

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

1

7점

n, \(q \le 1000\)

2

11점

\(l_{i} = 1\), for each \(1 \le i \le q\)

3

17점

\(m = 1\) or \(m = n\)

4

24점

n, \(q \le 5000\)

5

51점

No additional constraints.

예제 1
입력
7 3 3
4 2 3 7 1 6 5
4 7
3 5
1 4
출력
5
예제 2
입력
6 4 1
5 3 6 2 1 4
2 4
3 5
2 6
5 6
출력
2
예제 3
입력
8 2 5
8 7 6 5 4 3 1 2
2 8
1 7
출력
7
설명

Explanation of the first sample test: After executing the first command, the heights of the students
in the row are: 4 2 3 1 7 5 6. After executing the second command the heights are: 4 2 1 7 3 5 6. In the
end, after executing the third command, the row should look like this: 1 7 2 4 3 5 6. Marin should occupy
the 5th position from the left.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 4

평가 및 의견

Tjelesni

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

Log in to rate problems.

개별 의견

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

풀이 제출

Tjelesni

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