CF1521B.Nastia and a Good Array
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Nastia has received an array of n positive integers as a gift.
She calls such an array a good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers u and v.
You can perform the operation: select two different indices i,j (1≤i,j≤n, i=j) and two integers x,y (1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y). Then change ai to x and aj to y.
The girl asks you to make the array good using at most n operations.
It can be proven that this is always possible.
娜斯佳收到了一个由 n 个正整数组成的数组作为礼物。
她称一个数组 a 是“好的”,当且仅当对所有 i(2≤i≤n)均满足 gcd(ai−1,ai)=1,其中 gcd(u,v) 表示整数 u 和 v 的最大公约数(GCD)。
你可以执行如下操作:选择两个不同的下标 i,j(1≤i,j≤n,且 i=j)以及两个整数 x,y(1≤x,y≤2⋅109),使得 min(ai,aj)=min(x,y)。然后将 ai 修改为 x,并将 aj 修改为 y。
女孩请你至多使用 n 次操作,使该数组变为“好的”。
可以证明,这总是可行的。
输入格式
The first line contains a single integer t (1≤t≤10000) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤105) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the array which Nastia has received as a gift.
It's guaranteed that the sum of n in one test doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤10000),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),即 Nastia 收到的数组礼物。
保证单个测试中所有 n 的总和不超过 2⋅105。
输出格式
For each of t test cases print a single integer k (0≤k≤n) — the number of operations. You don't need to minimize this number.
In each of the next k lines print 4 integers i, j, x, y (1≤i=j≤n, 1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y) — in this manner you replace ai with x and aj with y.
If there are multiple answers, print any.
对于每个测试用例,输出一个整数 k(0≤k≤n)—— 表示操作次数。你无需最小化该数值。
接下来的 k 行中,每行输出四个整数 i、j、x、y(1≤i=j≤n,1≤x,y≤2⋅109),使得 min(ai,aj)=min(x,y) —— 据此,你将 ai 替换为 x,并将 aj 替换为 y。
若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#1
2 5 9 6 3 11 15 3 7 5 13
输出#1
2 1 5 11 9 2 5 7 6 0
说明/提示
Consider the first test case.
Initially a=[9,6,3,11,15].
In the first operation replace a1 with 11 and a5 with 9. It's valid, because min(a1,a5)=min(11,9)=9.
After this a=[11,6,3,11,9].
In the second operation replace a2 with 7 and a5 with 6. It's valid, because min(a2,a5)=min(7,6)=6.
After this a=[11,7,3,11,6] — a good array.
In the second test case, the initial array is already good.
考虑第一个测试用例。
初始时 a=[9,6,3,11,15]。
在第一次操作中,将 a1 替换为 11,同时将 a5 替换为 9。该操作合法,因为 min(a1,a5)=min(11,9)=9。
操作后,a=[11,6,3,11,9]。
在第二次操作中,将 a2 替换为 7,同时将 a5 替换为 6。该操作合法,因为 min(a2,a5)=min(7,6)=6。
操作后,a=[11,7,3,11,6] —— 这是一个“好”数组。
在第二个测试用例中,初始数组已经是“好”数组。
输入解题思路,AI测评打分。不知道怎么写?