#P12569. [UOI 2023] An Array and Partial Sums

[UOI 2023] An Array and Partial Sums

题目描述

A prefix sum array of an integer array aa of length nn is an array bb of length nn such that bi=a1+a2++aib_i = a_1+a_2+\ldots+a_i.

A suffix sum array of an integer array aa of length nn is an array bb of length nn such that bi=an+an1++aib_i = a_n+a_{n-1}+\ldots+a_i.

We call the normalization of an integer array aa of length nn performing the assignment aimax(min(ai,1018),1018)a_i \leftarrow \max(\min(a_i, 10^{18}),-10^{18}) for 1in1 \le i \le n.

An integer array aa of length nn is given.

We are allowed to perform operations of three types:

  • replace each element of array aa with its opposite (perform the assignment ai(ai)a_i \leftarrow (-a_i) for 1in1 \le i \le n);
  • select any subsegment of the array aa and replace it with the array of its prefix sums, then normalize array aa;
  • select any subsegment of the array aa and replace it with the array of its suffix sums, then normalize array aa.

Find the shortest sequence of operations required to make all elements of array aa non-negative.

Note that for some blocks of tests, it is allowed to find a sequence of operations that is not the shortest possible.

输入格式

The first line contains two integers nn and gg (1n21051 \le n \le 2 \cdot 10^5, 0g80 \le g \le 8) --- the length of the array and the test group number, respectively.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1-1 \le a_i \le 1) --- the elements of the array.

输出格式

In the first line, print a single integer mm~--- the minimum number of operations required to make all elements of the array aa non-negative.

In the next mm lines, output the descriptions of the operations. Output the descriptions of operations of the first type in the format "1\texttt{1}". Output the descriptions of operations of the second and third types in the formats "2 l r\texttt{2 l r}" and "3 l r\texttt{3 l r}", respectively, where ll and rr (1lrn1 \le l \le r \le n) denote the left and right boundaries of the subarray of the corresponding operation.

If there are multiple correct answers, any of them may be printed.

7 0
0 0 1 -1 -1 -1 1
2
3 1 3
2 1 7

提示

In the first example, the array aa changes twice:

  • after performing the third type of operation with parameters l=1l=1, r=3r=3, the array aa becomes equal to [1,1,1,1,1,1,1][1,1,1,-1,-1,-1,1];
  • after performing the second type of operation with parameters l=1l=1, r=7r=7, the array aa becomes equal to [1,2,3,2,1,0,1][1,2,3,2,1,0,1].

Scoring

Let the minimum number of operations required to make all elements of the array aa non-negative for a certain test be mansm_{ans}, and your solution uses muserm_{user} operations.

  • (1414 points): mans1m_{ans} \le 1;
  • (1717 points): your solution will be considered correct if muser100m_{user} \le 100. It can be proved that there always exists a sequence of no more than 100100 operations under the given constraints;
  • (1818 points): your solution will be considered correct if musermans+3m_{user} \le m_{ans} + 3;
  • (77 points): your solution will be considered correct if musermans+1m_{user} \le m_{ans} + 1;
  • (77 points): n3000n \le 3000; it is guaranteed that all shortest sequences of operations contain only operations of the second type;
  • (1919 points): it is guaranteed that all shortest sequences of operations contain only operations of the second type;
  • (1717 points): n3000n \le 3000;
  • (11 point): no additional constraints.