No.3184 Make Same
Problem Statement
You are given a sequence of non-negative integers $A = (A_1, A_2, \cdots, A_N)$ of length $N$. Here, $A$ is guaranteed to be non-decreasing.
Your goal is to make all elements of $A$ equal. To do so, you may perform the following operation up to $30$ times.
- Declare $3$ integers $l, r, v$ satisfying $1 \leq l \leq r \leq N, 0 \leq v \leq 10^9$.
- Then, for $i = l, l + 1, \cdots, r$, replace $A_i$ with $A_i + v$.
- Finally, sort $A$ in ascending order.
Input
$N$
$A_1\ \ A_2\ \ \cdots A_N$
- $1 \leq N \leq 2 \times 10^5$
- $0 \leq A_i \leq 10^9$
- $A_i \leq A_{i + 1}$
- All inputs are integers.
Output
If the goal can be achieved with $M$ operations, first output $M$ on the $1$st line.
Then output $M$ lines. On the $i$-th line, output $l, r, v$ declared in the $i$-th operation, separated by spaces.
Sample
Sample 1
Input
4
1 3 4 6
Output
4
2 3 4
1 1 6
1 1 2
1 2 1
- After the $1$st operation, $A = (1, 6, 7, 8)$.
- After the $2$nd operation, $A = (6, 7, 7, 8)$.
- After the $3$rd operation, $A = (7, 7, 8, 8)$.
- After the $4$th operation, $A = (8, 8, 8, 8)$.
Sample 2
Input
1
0
Output
0
If the goal is already achieved from the start, the number of operations may be $0$.
Sample 3
Input
3
1 2 3
Output
4
3 3 997
1 1 999
1 1 998
1 3 0
In the end, $A = (1000, 1000, 1000)$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂