#P15354. [COCI 2025/2026 #4] 体育课 / Tjelesni

    ID: 17318 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>线段树COCI(克罗地亚)2026

[COCI 2025/2026 #4] 体育课 / Tjelesni

Problem Description

You are given a permutation p1∼pnp_1 \sim p_n of 1∼n1 \sim n.

Apply qq operations to pp. In the ii-th operation, you are given li,ril_i, r_i, meaning:

  • Let S={pli,…,pri}S = \{p_{l_i}, \ldots, p_{r_i}\}.
  • For j=0,1,…,ri−lij = 0, 1, \ldots, r_i - l_i, perform the following steps:
    • If jj is even, let v=min⁡Sv = \min S; otherwise, let v=max⁡Sv = \max S.
    • Set pj+li←vp_{j + l_i} \gets v, and update S←S\{v}S \gets S \backslash \{v\} (that is, remove vv from SS).

Given a positive integer mm, find the position of the number mm after all qq operations.

Input Format

The first line contains three positive integers n,q,mn, q, m (1≤n,q≤1051 \le n, q \le 10^5, 1≤m≤n1 \le m \le n).

The second line contains nn positive integers p1,…,pnp_1, \ldots, p_n.

The next qq lines each contain two positive integers li,ril_i, r_i (1≤li≤ri≤n1 \le l_i \le r_i \le n).

Output Format

Output one positive integer in a single line, representing the position of the number mm after all operations.

7 3 3
4 2 3 7 1 6 5
4 7
3 5
1 4
5
6 4 1
5 3 6 2 1 4
2 4
3 5
2 6
5 6
2
8 2 5
8 7 6 5 4 3 1 2
2 8
1 7
7

Hint

Sample Explanation

Explanation for Sample 1:

  • After the first operation, p=[4,2,3,1,7,5,6]p = [4,2,3,1,7,5,6].
  • After the second operation, p=[4,2,1,7,3,5,6]p = [4,2,1,7,3,5,6].
  • After the third operation, p=[1,7,2,4,3,5,6]p = [1,7,2,4,3,5,6].

The position of the number 33 is 55.

Subtasks

Subtask ID Score Constraints
11 77 n,q≤1000n, q \le 1000
22 1111 li=1l_i = 1
33 1717 m∈{1,n}m \in \{1,n\}
44 2424 n,q≤5000n, q \le 5000
55 5151 No additional constraints.

Translated by ChatGPT 5