CF1687E.Become Big For Me

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Come, let's build a world where even the weak are not forgotten!

—Kijin Seija, Double Dealing Characters

Shinmyoumaru has a mallet that can turn objects bigger or smaller. She is testing it out on a sequence aa and a number vv whose initial value is 11. She wants to make v=gcd⁡i≠jai⋅ajv = \gcd\limits_{i\ne j}{a_i\cdot a_j} by no more than 10510^5 operations (gcd⁡i≠jai⋅aj\gcd\limits_{i\ne j}{a_i\cdot a_j} denotes the gcd⁡\gcd of all products of two distinct elements of the sequence aa).

In each operation, she picks a subsequence bb of aa, and does one of the followings:

  • Enlarge: v=v⋅lcm(b)v = v \cdot \mathrm{lcm}(b)
  • Reduce: v=vlcm(b)v = \frac{v}{\mathrm{lcm}(b)}

Note that she does not need to guarantee that vv is an integer, that is, vv does not need to be a multiple of lcm(b)\mathrm{lcm}(b) when performing Reduce.

Moreover, she wants to guarantee that the total length of bb chosen over the operations does not exceed 10610^6. Fine a possible operation sequence for her. You don't need to minimize anything.

来吧,让我们构建一个连弱者都不会被遗忘的世界!

——琪露诺·赛娅,《双重契约》

神明丸拥有一把可以将物体变大或变小的木槌。她正在对一个序列 aa 和一个初始值为 11 的数 vv 进行测试。她的目标是通过至多 10510^5 次操作,使得 v=gcd⁡i≠jai⋅ajv = \gcd\limits_{i\ne j}{a_i\cdot a_j}(此处 gcd⁡i≠jai⋅aj\gcd\limits_{i\ne j}{a_i\cdot a_j} 表示序列 aa 中所有互异下标元素两两乘积的最大公约数)。

每次操作中,她从 aa 中选取一个子序列 bb,并执行以下两种操作之一:

  • 放大:v=v⋅lcm(b)v = v \cdot \mathrm{lcm}(b)
  • 缩小:v=vlcm(b)v = \frac{v}{\mathrm{lcm}(b)}

注意:她无需保证 vv 始终为整数,即在执行“缩小”操作时,vv 不必是 lcm(b)\mathrm{lcm}(b) 的倍数。

此外,她希望确保所有操作中所选子序列 bb 的总长度(即所有 ∣b∣|b| 之和)不超过 10610^6。请为她构造一个可行的操作序列。你无需最小化任何量。

输入格式

The first line contains a single integer nn (2≤n≤1052\leq n\leq 10^5) — the size of sequence aa.

The second line contains nn integers a1,a2,⋯ ,ana_1,a_2,\cdots,a_n (1≤ai≤1061\leq a_i\leq 10^6) — the sequence aa.

It can be shown that the answer exists.

第一行包含一个整数 nn(2≤n≤1052\leq n\leq 10^5)——序列 aa 的长度。

第二行包含 nn 个整数 a1,a2,⋯ ,ana_1,a_2,\cdots,a_n(1≤ai≤1061\leq a_i\leq 10^6)——序列 aa。

可以证明答案一定存在。

输出格式

The first line contains a non-negative integer kk (0≤k≤1050\leq k\leq 10^5) — the number of operations.

The following kk lines contains several integers. For each line, the first two integers ff (f∈0,1f\in{0,1}) and pp (1≤p≤n1\le p\le n) stand for the option you choose (00 for Enlarge and 11 for Reduce) and the length of bb. The other pp integers of the line i1,i2,…,ipi_1,i_2,\ldots,i_p (1≤i1<i2<…<ip≤n1\le i_1 \lt i_2 \lt \ldots \lt i_p\le n) represents the indexes of the subsequence. Formally, bj=aijb_j=a_{i_j}.

第一行包含一个非负整数 kk(0≤k≤1050\leq k\leq 10^5)—— 表示操作次数。

接下来的 kk 行每行包含若干个整数。对于每一行,前两个整数 ff(f∈{0,1}f\in\{0,1\})和 pp(1≤p≤n1\le p\le n)分别表示所选操作(00 表示“放大”,11 表示“缩小”)以及子序列 bb 的长度;该行其余 pp 个整数 i1,i2,…,ipi_1,i_2,\ldots,i_p(1≤i1<i2<…<ip≤n1\le i_1 \lt i_2 \lt \ldots \lt i_p\le n)表示子序列的下标。形式化地,有 bj=aijb_j=a_{i_j}。

输入输出样例

  • 输入#1

    3
    6 10 15

    输出#1

    1
    0 3 1 2 3
  • 输入#2

    4
    2 4 8 16

    输出#2

    2
    0 1 4
    1 1 1

说明/提示

Test case 1:

gcd⁡i≠jai⋅aj=gcd⁡60,90,150=30\gcd\limits_{i\ne j}{a_i\cdot a_j}=\gcd{60,90,150}=30.

Perform v=v⋅lcm⁡a1,a2,a3=30v = v\cdot \operatorname{lcm}{a_1,a_2,a_3}=30.

Test case 2:

gcd⁡i≠jai⋅aj=8\gcd\limits_{i\ne j}{a_i\cdot a_j}=8.

Perform v=v⋅lcm⁡a4=16v = v\cdot \operatorname{lcm}{a_4}=16.

Perform v=vlcm⁡a1=8v = \frac{v}{\operatorname{lcm}{a_1}}=8.

测试用例 1:

gcd⁡i≠jai⋅aj=gcd⁡60,90,150=30\gcd\limits_{i\ne j}{a_i\cdot a_j}=\gcd{60,90,150}=30。

执行 v=v⋅lcm⁡a1,a2,a3=30v = v\cdot \operatorname{lcm}{a_1,a_2,a_3}=30。

测试用例 2:

gcd⁡i≠jai⋅aj=8\gcd\limits_{i\ne j}{a_i\cdot a_j}=8。

执行 v=v⋅lcm⁡a4=16v = v\cdot \operatorname{lcm}{a_4}=16。

执行 v=vlcm⁡a1=8v = \frac{v}{\operatorname{lcm}{a_1}}=8。

输入解题思路,AI测评打分。不知道怎么写?

首页