問題一覧 > 通常問題

No.1404 誕生日プレゼント

レベル : / 実行時間制限 : 1ケース 3.153秒 / メモリ制限 : 315 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 6
作問者 : CuriousFairy315 / テスター : cn_449
お気に入りにしたユーザー ProblemId : 4950 / 自分の提出
問題文最終更新日: 2021-02-18 13:52:04
Birthday Present
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. Show the original
yukicoder contest 283 (順位表) の他の問題:

Problem Statement

315-san is going to give a sequence to a close friend, Nekkoara-san, as a birthday present.
Nekkoara-san likes the sequence $B_i$ of length $N$, so 315-san prepared this sequence and headed for Nekkoara-san's house.
However, on checking the sequence while on the train, 315-san realized that a different sequence $A_i$ had been brought by mistake.
Fortunately, there are still $P$ minutes until arrival. Per $1$ minute, 315-san can perform either of the following operations only once.
Operation 1. Choose integers $i, j$ such that $1 \leq i, j \leq N$, and add $A_j$ to $A_i$.
Operation 2. Replace every element of the sequence with its remainder modulo $P$.
Now, can 315-san successfully give the sequence $B_i$?

Input

$N \ P$
$A_1 \ A_2 \ \cdots \ A_N$
$B_1 \ B_2 \ \cdots \ B_N$

  • $1 \leq N \leq 10^5$
  • $P = 223577$ (prime)
  • $0 \leq A_i, B_i < P$
  • All inputs are integers.

Output

If the sequence $B_i$ cannot be made in time, print -1.
Otherwise, first print the number of operations performed, $n$, on the $1$st line.
On each of the following $n$ lines, print $1 \ i \ j$ if operation $1$ was performed, or $2$ if operation $2$ was performed.
In either case, print a newline at the end.

Sample

Sample 1
Input
2 223577
1 1
4 5
Output
5
1 1 2
1 1 2
1 1 2
1 2 1
2

It turns out that performing operation 2 only at the end causes no problem.

Sample 2
Input
1 223577
101090
9
Output
11
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
2

You may specify the same number for both.

Sample 3
Input
5 223577
1 2 3 4 5
1 3 6 10 15
Output
10
1 5 4
1 5 3
1 5 2
1 5 1
1 4 3
1 4 2
1 4 1
1 3 2
1 3 1
1 2 1

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