Need help in a problem

Правка en2, от sai_123_sai, 2023-07-30 21:10:49

`You are given an array A containing N integers A[1], A[2], ..., A[N]. In one operation, you can choose two integers 1 ≤ i, j ≤ N, i ≠ j and change A[i] to A[i] ^ A[j], where ^ represents the XOR operation.

You need to make the array non-decreasing using at most 4 * N such operations.

Input format

First line contains an integer T, the number of testcases. Each testcase contains 2 lines: First line contains an integer N, the size of the array. Second line contains N space-separated integers. Output format For each testcase:

First line should print an integer 0 ≤ M ≤ 4 * N, the number of operations you want to make. Next M lines should contain the operations you want to make to make this array non-decreasing. Each line should contain two space-separated integers — i and j respectively, such that A[i] is changed to A[i] ^ A[j]. Constraints 1 ≤ N ≤ 100,000 1 ≤ Sum of N over all testcases ≤ 400,000 0 ≤ A_i < 2^30 Sample 0 Input 3 2 0 1 2 1 0 3 2 1 0 Output 0 1 2 1 3 2 1 3 2 1 3 Explanation For the first test case, the array is already non decreasing, so no operations are required. For the second test case, we need only one operation i=2, j=1. This causes A[2] to change into 0 ^ 1 which is 1. Hence, the array becomes 1 1 and is non-decreasing. For the third test case, the array changes as follow [2,1,0] -> [2,3,0] -> [2,3,3] -> [1,3,3] and its non-decreasing` can anyone help me with the solution of this problem ?

Теги icpc

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский sai_123_sai 2023-08-01 16:15:56 1410
en2 Английский sai_123_sai 2023-07-30 21:10:49 20
en1 Английский sai_123_sai 2023-07-30 21:09:05 1503 Initial revision (published)