#P6138. [IOI 2012] 骑马比武竞赛

[IOI 2012] 骑马比武竞赛

Description

In 1491, Duke Milan Lodovico Sforza asked Leonardo to prepare the celebration for his wedding with Beatrice d'Este. The celebration included a grand three-day jousting tournament, but the most popular knight was late...

In a jousting tournament, NN knights are initially lined up in a row and numbered from 00 to N1N-1 according to their positions. In each round, the host calls two positions SS and EE (where 0S<EN10 \le S < E \le N - 1). All knights whose positions are between SS and EE (inclusive) start jousting. The final winner stays in the tournament and returns to his original position, while all losers leave the tournament. After that, the remaining knights close ranks in their original order, filling the empty positions. Their positions are then renumbered from 00 to N(ES)1N - (E - S) - 1. The host then proceeds to the next round, until only one knight remains.

Leonardo knows that all knights have different strengths, ranging from 00 (weakest) to N1N-1 (strongest). He also knows exactly what commands the host will give for CC rounds, because Leonardo can do anything. He is also sure that in each round, the knight with the greatest strength will win.

Among the NN knights, N1N-1 knights have already lined up, but the most popular knight has not appeared yet. This late knight has strength RR. To make the tournament reach its climax, Leonardo wants this knight to show his style well, so he wants to insert him into a position such that he can win the maximum number of rounds. Note that we do not care about rounds that do not involve this knight. We only care about rounds that include this knight and are won by him.

Example

Suppose there are 55 knights, and 44 of them have already lined up with strengths [1,0,2,4][1,0,2,4]. The late knight has strength 33. Suppose there will be 33 rounds, and the host plans to call positions (S,E)(S,E) as (1,3)(1, 3), (0,1)(0, 1), (0,1)(0, 1).

If Leonardo inserts the late knight into the first position, then the strengths become [3,1,0,2,4][3, 1, 0, 2, 4]. In the first round, the knights at positions 1,2,31,2,3 participate, with strengths 1,0,21,0,2, so the knight with strength 22 wins. After this round, the new sequence of strengths becomes [3,2,4][3, 2, 4]. In the next round, the knights with strengths 33 and 22 (positions 0,10,1) compete, and the knight with strength 33 wins. The sequence then becomes [3,4][3,4]. In the last round (positions 0,10,1), the knight with strength 44 wins. Therefore, the late knight wins only one round (the second round).

If Leonardo inserts the late knight between the knights with strengths 11 and 00, then the strengths become [1,3,0,2,4][1,3,0,2,4]. This time, in the first round the participating strengths are 3,0,23,0,2. The knight with strength 33 wins, and the sequence becomes [1,3,4][1,3,4]. In the second round, the knight with strength 11 faces the knight with strength 33, and the knight with strength 33 wins. In the last round, the sequence becomes [3,4][3,4], and the knight with strength 44 wins. In this arrangement, the late knight wins two rounds. This is actually the best position, because no other position allows the late knight to win more than two rounds.

Your task is to write a program to help the late knight choose the best position so that he can win the maximum number of rounds, meeting Leonardo’s expectations.

Input Format

  • The first line contains 33 integers NN, CC, RR, where NN is the number of knights, CC is the number of rounds the host will conduct, and RR is the strength of the late knight.
  • The second line contains N1N-1 integers K[0],K[1],,K[N2]K[0],K[1],\cdots,K[N-2], representing the strengths of the N1N-1 knights already lined up.
  • The third line contains 2C2C integers S[0],E[0],S[1],E[1],,S[C1],E[C1]S[0],E[0],S[1],E[1],\cdots,S[C-1],E[C-1]. For 0iC10 \le i \le C-1, in round i+1i+1 the host makes the knights from position S[i]S[i] to position E[i]E[i] (inclusive) compete. You may assume that for each ii, S[i]<E[i]S[i] < E[i].

Output Format

Output one line: the position that allows the late knight to win the maximum number of rounds. If there are multiple optimal positions, output the smallest index.

5 3 3
1 0 2 4
1 3
0 1
0 1

1

Hint

For 100%100\% of the data, 1N1051 \le N \le 10^5, 1CN11 \le C \le N-1. In round i+1i+1, E[i]E[i] is less than the number of knights remaining in that round. After the CC commands, there will be only one knight left.

Translated by ChatGPT 5