CF1797E.Li Hua and Array
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Li Hua wants to solve a problem about φ — Euler's totient function. Please recall that φ(x)=i=1∑x[gcd(i,x)=1].†,‡
He has a sequence a1,a2,⋯,an and he wants to perform m operations:
- "1 l r" (1≤l≤r≤n) — for each x∈[l,r], change ax into φ(ax).
- "2 l r" (1≤l≤r≤n) — find out the minimum changes needed to make sure al=al+1=⋯=ar. In each change, he chooses one x∈[l,r], change ax into φ(ax). Each operation of this type is independent, which means the array doesn't actually change.
Suppose you were Li Hua, please solve this problem.
† gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y.
‡ The notation [cond] equals 1 if the condition cond is true, and 0 otherwise.
李华想解决一个关于欧拉函数 φ 的问题。请回忆:φ(x)=i=1∑x[gcd(i,x)=1]。†,‡
他有一个序列 a1,a2,⋯,an,并要执行 m 个操作:
- “1 l r”(1≤l≤r≤n)——对每个 x∈[l,r],将 ax 替换为 φ(ax)。
- “2 l r”(1≤l≤r≤n)——求出使 al=al+1=⋯=ar 所需的最少变换次数。每次变换中,他选择一个 x∈[l,r],将 ax 替换为 φ(ax)。此类操作相互独立,即数组实际并不发生改变。
假设你是李华,请解决该问题。
† gcd(x,y) 表示整数 x 与 y 的最大公约数(GCD)。
‡ 记号 [cond] 在条件 cond 成立时取值为 1,否则为 0。
输入格式
The first line contains two integers n and m (1≤n,m≤105) — the number of elements in the array and the number of operations to process, respectively.
The second line contains n integers a1,a2,⋯,an (1≤ai≤5⋅106) — the elements of the array.
Next m lines, each line contains three integers ti,li,ri (ti∈1,2,1≤li≤ri≤n) — the i-th operation.
第一行包含两个整数 n 和 m(1≤n,m≤105)—— 分别表示数组的元素个数和需要处理的操作个数。
第二行包含 n 个整数 a1,a2,⋯,an(1≤ai≤5⋅106)—— 数组的元素。
接下来 m 行,每行包含三个整数 ti,li,ri(ti∈{1,2},1≤li≤ri≤n)—— 第 i 个操作。
输出格式
For each "2 l r", output the answer in an separate line.
对于每个“2 l r”,在单独一行中输出答案。
输入输出样例
输入#1
5 4 8 1 6 3 7 2 1 5 2 3 4 1 1 3 2 3 4
输出#1
10 2 1
说明/提示
Denote φk(x)={x,φ(φk−1(x)),k=0k>0.
At first, a=[8,1,6,3,7].
To make sure a1=a2=a3=a4=a5, we can change a to a′=[φ3(8),φ0(1),φ2(6),φ2(3),φ3(7)]=[1,1,1,1,1], using 3+0+2+2+3=10 changes.
To make sure a3=a4, we can change a to a′=[φ0(8),φ0(1),φ1(6),φ1(3),φ0(7)]=[8,1,2,2,7], using 0+0+1+1+0=2 changes.
After "1 1 3", a is changed to a=[φ1(8),φ1(1),φ1(6),φ0(3),φ0(7)]=[4,1,2,3,7].
To make sure a3=a4, we can change a to a′=[φ0(4),φ0(1),φ0(2),φ1(3),φ0(7)]=[4,1,2,2,7], using 0+0+0+1+0=1 change.
记 φk(x)={x,φ(φk−1(x)),k=0k>0。
初始时,a=[8,1,6,3,7]。
为使 a1=a2=a3=a4=a5,可将 a 变为 a′=[φ3(8),φ0(1),φ2(6),φ2(3),φ3(7)]=[1,1,1,1,1],共需 3+0+2+2+3=10 次变换。
为使 a3=a4,可将 a 变为 a′=[φ0(8),φ0(1),φ1(6),φ1(3),φ0(7)]=[8,1,2,2,7],共需 0+0+1+1+0=2 次变换。
执行操作 “1 1 3” 后,a 变为 a=[φ1(8),φ1(1),φ1(6),φ0(3),φ0(7)]=[4,1,2,3,7]。
为使 a3=a4,可将 a 变为 a′=[φ0(4),φ0(1),φ0(2),φ1(3),φ0(7)]=[4,1,2,2,7],共需 0+0+0+1+0=1 次变换。
输入解题思路,AI测评打分。不知道怎么写?