luogu#P16363. [OOI 2026] Participants entry

[OOI 2026] Participants entry

Problem Description

At the open programming olympiad for school students, there are nn participants numbered from 11 to nn. Participant number ii is wearing a t-shirt of color aia_i. The organizers of the competition plan to invite participants to the competition hall in turn. To make this process visually pleasing, they want to avoid situations where two consecutive participants enter wearing t-shirts of the same color. To achieve this, participants will be invited according to the following algorithm:

  • The first participant to enter the competition hall is participant number 11.
  • invited must have a t-shirt color that differs from the color of the last participant who entered. If there are several such participants, the one with the smallest number is chosen.
  • Finally, if all remaining participants have the same t-shirt color as the last participant who entered, all remaining participants are invited in increasing order of their numbers.

On the night before the olympiad, the organizers prepared a plan for the participants entry, but just before the opening, they noticed that participants with neighboring numbers sometimes swap t-shirts. Of course, this led to the previous plan no longer complying with the rules, and the organizers needed to develop a new one.

You are required to respond to two types of queries:

  • Two participants with numbers xix_i and (xi+1)(x_i + 1) swap t-shirts.
  • Find out the order in which participant number yiy_i will enter if participants start entering according to the algorithm described above, starting from the first one, taking into account all previous t-shirt swaps.

Input Format

The first line contains two integers nn and qq (1n5000001 \le n \le 500\,000, 1q5000001 \le q \le 500\,000) --- the number of participants in the competition and the number of queries.

The second line contains nn integers a1a_1, a2a_2, \ldots, ana_n (1ain1 \le a_i \le n) --- the initial colors of the participants' t-shirts in the order of their numbering.

The following qq lines describe the queries. In the ii-th line, there is an integer tit_i (1ti21 \le t_i \le 2) --- the type of the ii-th query.

  • If ti=1t_i = 1, then the next line contains an integer xix_i (1xi<n1 \le x_i < n). In this case, in the ii-th query, participants with numbers xix_i and (xi+1)(x_i + 1) swap t-shirts.
  • If ti=2t_i = 2, then the next line contains an integer yiy_i (1yin1 \le y_i \le n). In this case, in the ii-th query, you need to find out the order in which participant number yiy_i will enter if participants start entering according to the algorithm described above, starting from the first one, taking into account all previous t-shirt swaps.

Output Format

For each query of the second type, you should output a single integer on a separate line --- the answer to the query.

It is guaranteed that there is at least one query of the second type.

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

Hint

Note

In the first example for the problem, in the initial configuration, participants enter the competition hall in the order:

$$1, \quad 2, \quad 4, \quad 3, \quad 5, \quad 6, \quad 8, \quad 7, \quad 9, \quad 10$$

That is, participant number 22 enters second, participant number 33 enters fourth, participant number 44 enters third, and participant number 1010 enters tenth.

After participants with numbers 11 and 22 swap t-shirts, the t-shirt colors of the participants are as follows:

$$1, \quad 3, \quad 1, \quad 2, \quad 2, \quad 1, \quad 1, \quad 2, \quad 2, \quad 2$$

Therefore, after this change, participants will enter the competition hall in the order:

$$1, \quad 2, \quad 3, \quad 4, \quad 6, \quad 5, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 22 will enter second, participant number 33 will enter third, participant number 44 will enter fourth, participant number 55 will enter sixth, and participant number 1010 will enter tenth.

In the second example for the problem, in the initial configuration, participants enter the competition hall in the order:

$$1, \quad 2, \quad 5, \quad 3, \quad 6, \quad 4, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 11 enters first.

After participants with numbers 11 and 22 swap t-shirts, the t-shirt colors of the participants are as follows:

$$2, \quad 1, \quad 2, \quad 2, \quad 3, \quad 4, \quad 5, \quad 6, \quad 7, \quad 8$$

Therefore, after this change, participants will enter in the order:

$$1, \quad 2, \quad 3, \quad 5, \quad 4, \quad 6, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 22 enters second.

After participants with numbers 22 and 33 swap t-shirts, the t-shirt colors of the participants are as follows:

$$2, \quad 2, \quad 1, \quad 2, \quad 3, \quad 4, \quad 5, \quad 6, \quad 7, \quad 8$$

Therefore, after this change, participants will enter the competition hall in the order:

$$1, \quad 3, \quad 2, \quad 5, \quad 4, \quad 6, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 33 enters second.

After participants with numbers 33 and 44 swap t-shirts, the t-shirt colors of the participants are as follows:

$$2, \quad 2, \quad 2, \quad 1, \quad 3, \quad 4, \quad 5, \quad 6, \quad 7, \quad 8$$

Therefore, after this change, participants will enter in the order:

$$1, \quad 4, \quad 2, \quad 5, \quad 3, \quad 6, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 44 enters second.

After participants with numbers 44 and 55 swap t-shirts, the t-shirt colors of the participants are as follows:

$$2, \quad 2, \quad 2, \quad 3, \quad 1, \quad 4, \quad 5, \quad 6, \quad 7, \quad 8$$

Therefore, after this change, participants will enter in the order:

$$1, \quad 4, \quad 2, \quad 5, \quad 3, \quad 6, \quad 7, \quad 8, \quad 9, \quad 10$$

That is, participant number 33 enters fifth, and participant number 55 enters fourth.

Scoring

The tests for this problem consist of 12 groups. Points for each group are awarded only if all tests in the group and all tests in some of the previous groups are passed. Note that passing the tests from the statement is not required for some groups. Offline verification\textbf{Offline verification} means that the results of testing your solution on this group will only be available after the competition ends. The final score for each group is equal to the maximum score obtained for this group of tests across all submitted solutions.

Group Points Additional constraints Required groups Comment
n,qn, q
0 -- Tests from the statement.
1 7 n,q500n, q \le 500 0
2 9 n,q5000n, q \le 5\,000 0, 1
3 5 n,q10000n, q \le 10\,000 0--2
4 10 n,q100000n, q \le 100\,000 0--3
5 8 n,q200000n, q \le 200\,000 0--4
6 7 n,q300000n, q \le 300\,000 0--5
7 9 -- -- 1ai21 \le a_i \le 2
8 7 1ai51 \le a_i \le 5
9 11 -- For any iji \neq j: ai=1a_i = 1 or aiaja_i \neq a_j
If ti=2t_i = 2, then yi=9n10y_i = \left\lceil \frac{9n}{10}\right\rceil
10 8 9 For any iji \neq j: ai=1a_i = 1 or aiaja_i \neq a_j
11 9 If ti=2t_i = 2, then yi=9n10y_i = \left\lceil \frac{9n}{10}\right\rceil
12 8 0--11 Offline testing.