#P9746. Sequence Reduction via XOR Operations
Sequence Reduction via XOR Operations
Sequence Reduction via XOR Operations
You are given a sequence of n integers \(a_1,a_2,\ldots,a_n\). You are allowed to perform several (possibly 0) operations on the sequence. In each operation, you choose three positive integers \(i, j, k\) with \(i < j < k\) (and \(k\) not exceeding the current length of the sequence) such that
[ a_i \oplus a_j \oplus a_k = 0 ]
Let
[ s = a_i \oplus a_{i+1} \oplus \cdots \oplus a_k ]
Then remove the subarray \(a_i, a_{i+1},\ldots,a_k\) and insert the single number \(s\) in its position. (Note that the length of the sequence decreases by \(k-i\) after this move.)
Your task is to decide whether it is possible to reduce the sequence to a single number (i.e. the final sequence has length 1) by applying a sequence of such operations. If it is possible, you must output one valid sequence of operations.
Note: In all formulas above, \(\oplus\) denotes the bitwise XOR operation and all formulas are given in \(\LaTeX\) format.
inputFormat
The first line contains a single integer \(n\) (the length of the sequence). The second line contains \(n\) space‐separated integers \(a_1, a_2, \ldots, a_n\).
outputFormat
If it is impossible to reduce the sequence to exactly one number, output a single line containing NO
. Otherwise, on the first line output YES
. On the second line output an integer \(m\) representing the number of operations. Then output \(m\) lines, each containing three space‐separated integers \(i,j,k\) representing an operation. The operations must be valid and transform the sequence into a single number.
If multiple answers exist, output any one of them.
sample
1
5
YES
0