#P7362. [eJOI 2020] XOR Sort (Day2)

[eJOI 2020] XOR Sort (Day2)

Description

Given a sequence AiA_i of length NN, you can perform the following operation:

Choose a position ii and change AiA_i to AiAi+1A_i \oplus A_{i+1} or AiAi1A_i \oplus A_{i-1}.

You want to know how many operations are needed to make AiA_i become:

  • S=1S=1, a strictly increasing sequence, i.e. Ai<Ai+1A_i < A_{i+1}.
  • S=2S=2, a non-strictly increasing sequence, i.e. AiAi+1A_i \le A_{i+1}.

Input Format

The first line contains two integers N,SN, S, representing the length of the sequence and the test point type.
The second line contains NN integers AiA_i, representing the sequence.

Output Format

The first line contains an integer KK, representing the number of operations. You do not need to minimize KK; you only need to satisfy 0K4×1040 \le K \le 4 \times 10^4.
The next KK lines each contain two integers i,ji, j, meaning to change AiA_i to AiAjA_i \oplus A_j, where j=i+1j=i+1 or j=i1j=i-1.

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

Hint

Explanation for Sample 1

$$[3, 2, 8, 4, 1] \to [\mathbf 1, 2, 8, 4, 1] \to [1, 2, 8, \mathbf{12}, 1] \to [1, 2, 8, 12, \mathbf{ 13}]$$

Explanation for Sample 2

$$[4, 4, 2, 0, 1] \to [4, 4, \mathbf6, 0, 1] \to [4, 4, 6, \mathbf6, 1] \to [4, 4, 6, 6, \mathbf7]$$

Constraints

This problem uses bundled testdata.

  • Subtask 1 (25 pts): 2N1502 \le N \le 150, S=1S=1, and all AiA_i are distinct.
  • Subtask 2 (35 pts): 2N2002 \le N \le 200, S=1S=1, and all AiA_i are distinct.
  • Subtask 3 (40 pts): 2N10002 \le N \le 1000, S=2S=2.

For 100%100\% of the testdata:

  • 1S21 \le S \le 2.
  • 2N10002 \le N \le 1000.
  • 0Ai<2200 \le A_i < 2^{20}.

This problem uses Special Judge.

Note

Translated from eJOI 2020 Day2 A XOR Sort

Translated by ChatGPT 5