問題一覧 > 通常問題

No.1386 Range add Simulation

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 4
作問者 : 蜜蜂 / テスター : cardano1016 Mitarushi
お気に入りにしたユーザー ProblemId : 5805 / 自分の提出
問題文最終更新日: 2021-03-23 18:36:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
灘高入試コンテスト2021 (順位表) の他の問題:

Problem Statement

Mitsubachi-kun has a sequence $\ A\ $ consisting of $\ N\ $ elements.
Let $A_i\ $ be the $\ i\ $-th element of $\ A\ $. Currently, $\ A_i=0\ $ holds for all integers $\ i\ $ satisfying $\ 1 \leq i \leq N\ $.

Mitsubachi-kun will now perform operations $\ Q\ $ times. The $\ i\ $-th operation is described as follows.

    If $C_i=1\ $: for all integers $\ j\ $ satisfying $S_i \leq j \leq N\ $, add $\ (j-S_i+1)^2\ $ to $A_j\ $.
    If $C_i=2\ $: for all integers $\ j\ $ satisfying $1 \leq j \leq S_i\ $, add $\ (S_i-j+1)^2\ $ to $A_j\ $.

After the $Q\ $ operations, Mitsubachi-kun hands you a sequence $\ B\ $ consisting of $\ N\ $ elements.
Let $B_i\ $ be the $\ i\ $-th element of $\ B\ $. Currently, $\ B_i=0\ $ holds for all integers $\ i\ $ satisfying $\ 1 \leq i \leq N\ $.

Your goal is to make $A\ $ and $\ B\ $ identical.
You may perform the following operations up to $\ 410000\ $ times in total.

    Operation $\ 1$ : Choose one integer $\ i\ $ satisfying $1 \leq i \leq N\ $. Add $\ 1\ $ to $B_i\ $.
    Operation $\ 2$ : Choose one integer $\ i\ $ satisfying $1 \leq i \leq N\ $. Subtract $\ 1\ $ from $B_i\ $.
    Operation $\ 3$ : Choose integers $\ i,j\ $, one each, satisfying $1 \leq i,j \leq N\ $ and $\ |i-j| \leq 1\ $. Add $\ B_j\ $ to $B_i\ $.
    Operation $\ 4$ : Choose integers $\ i,j\ $, one each, satisfying $1 \leq i,j \leq N\ $ and $\ |i-j| \leq 1\ $. Subtract $\ B_j\ $ from $B_i\ $.

Note that in operations $\ 3,4\ $, you may choose $\ i,j\ $ such that $\ i=j\ $.

However, since Mitsubachi-kun complains a lot, you also must not perform operations such that, during the process, there exists an integer $\ i\ $ with $\ |B_i| > 10^{17}\ $.

Under the constraints of this problem, it can be shown that there exists a way of operating that makes $\ A\ $ and $\ B\ $ identical without Mitsubachi-kun complaining, so output one.
If multiple outputs satisfy the conditions, any of them will be accepted.

Input

$N\ \ Q$
$C_1\ \ S_1$
$C_2\ \ S_2$
$\vdots$
$C_Q\ \ S_Q$

  • $1 \leq N \leq 10^5$
  • $1 \leq Q \leq 5 \times 10^4$
  • $1 \leq C_i \leq 2(1 \leq i \leq Q)$
  • $1 \leq S_i \leq N(1 \leq i \leq Q)$
  • All inputs are integers

Output

On line $1\ $, output $\ X\ $, the number of operations.
As stated in the problem statement, $\ X\ $ must be an integer satisfying $\ 0 \leq X \leq 410000\ $.

Starting from line $2\ $, output the operations over $\ X\ $ lines. For each integer $\ i\ $ satisfying $2 \leq i \leq X+1\ $, the output on line $i\ $ represents the $\ i-1\ $-th operation.

For operation $\ 1\ $, output as follows.

1 i
This indicates that operation $\ 1\ $ was chosen with the output $\ i\ $, that is, that the operation of adding $\ 1\ $ to $\ B_i\ $ was performed.
Therefore, $i\ $ must be an integer satisfying $\ 1 \leq i \leq N\ $.

For operation $\ 2\ $, output as follows.

2 i
This indicates that operation $\ 2\ $ was chosen with the output $\ i\ $, that is, that the operation of subtracting $\ 1\ $ from $\ B_i\ $ was performed.
Therefore, $i\ $ must be an integer satisfying $\ 1 \leq i \leq N\ $.

For operation $\ 3\ $, output as follows.

3 i j
This indicates that operation $\ 3\ $ was chosen with the output $\ i, j\ $, that is, that the operation of adding $\ B_j\ $ to $\ B_i\ $ was performed.
Therefore, $i,j\ $ must be integers satisfying $\ 1 \leq i,j \leq N\ $ and $\ |i-j| \leq 1\ $.

For operation $\ 4\ $, output as follows.

4 i j
This indicates that operation $\ 4\ $ was chosen with the output $\ i, j\ $, that is, that the operation of subtracting $\ B_j\ $ from $\ B_i\ $ was performed.
Therefore, $i,j\ $ must be integers satisfying $\ 1 \leq i,j \leq N\ $ and $\ |i-j| \leq 1\ $.

From the above, the output consists of $\ X+1\ $ lines.
Print a newline at the end of each line of the output.

Sample

Sample 1
Input
4 3
1 3
2 1
1 4
Output
9
1 2
3 1 2
3 3 2
1 3
3 4 3
3 4 3
2 3
1 4
4 2 1

$A\ $ changes as follows.

$0,0,0,0 \rightarrow 0,0,1,4 \rightarrow 1,0,1,4 \rightarrow 1,0,1,5$

Also, $B\ $ changes as follows.

$0,0,0,0 \rightarrow 0,1,0,0 \rightarrow 1,1,0,0 \rightarrow 1,1,1,0 \rightarrow 1,1,2,0 \rightarrow 1,1,2,2 \rightarrow 1,1,2,4 \rightarrow 1,1,1,4 \rightarrow 1,1,1,5 \rightarrow 1,0,1,5$

Therefore, after the operations both $\ A,B\ $ are $\ 1,0,1,5\ $, so this output is correct.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。