CF1797E.Li Hua and Array

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Li Hua wants to solve a problem about φ\varphi — Euler's totient function. Please recall that φ(x)=∑i=1x[gcd⁡(i,x)=1]\varphi(x)=\sum\limits_{i=1}^x[\gcd(i,x)=1].†,‡^{\dagger,\ddagger}

He has a sequence a1,a2,⋯ ,ana_1,a_2,\cdots,a_n and he wants to perform mm operations:

  • "1 ll rr" (1≤l≤r≤n1\le l\le r\le n) — for each x∈[l,r]x\in[l,r], change axa_x into φ(ax)\varphi(a_x).
  • "2 ll rr" (1≤l≤r≤n1\le l\le r\le n) — find out the minimum changes needed to make sure al=al+1=⋯=ara_l=a_{l+1}=\cdots=a_r. In each change, he chooses one x∈[l,r]x\in[l,r], change axa_x into φ(ax)\varphi(a_x). Each operation of this type is independent, which means the array doesn't actually change.

Suppose you were Li Hua, please solve this problem.

†^\dagger gcd⁡(x,y)\gcd(x,y) denotes the greatest common divisor (GCD) of integers xx and yy.

‡^\ddagger The notation [cond][\textrm{cond}] equals 11 if the condition cond\textrm{cond} is true, and 00 otherwise.

李华想解决一个关于欧拉函数 φ\varphi 的问题。请回忆:φ(x)=∑i=1x[gcd⁡(i,x)=1]\varphi(x)=\sum\limits_{i=1}^x[\gcd(i,x)=1]。†,‡^{\dagger,\ddagger}

他有一个序列 a1,a2,⋯ ,ana_1,a_2,\cdots,a_n,并要执行 mm 个操作:

  • “1 ll rr”(1≤l≤r≤n1\le l\le r\le n)——对每个 x∈[l,r]x\in[l,r],将 axa_x 替换为 φ(ax)\varphi(a_x)。
  • “2 ll rr”(1≤l≤r≤n1\le l\le r\le n)——求出使 al=al+1=⋯=ara_l=a_{l+1}=\cdots=a_r 所需的最少变换次数。每次变换中,他选择一个 x∈[l,r]x\in[l,r],将 axa_x 替换为 φ(ax)\varphi(a_x)。此类操作相互独立,即数组实际并不发生改变。

假设你是李华,请解决该问题。

†^\dagger gcd⁡(x,y)\gcd(x,y) 表示整数 xx 与 yy 的最大公约数(GCD)。

‡^\ddagger 记号 [cond][\textrm{cond}] 在条件 cond\textrm{cond} 成立时取值为 11,否则为 00。

输入格式

The first line contains two integers nn and mm (1≤n,m≤1051\le n,m\le 10^{5}) — the number of elements in the array and the number of operations to process, respectively.

The second line contains nn integers a1,a2,⋯ ,ana_{1},a_{2},\cdots ,a_{n} (1≤ai≤5⋅1061\le a_{i}\le 5\cdot 10^{6}) — the elements of the array.

Next mm lines, each line contains three integers ti,li,rit_{i},l_{i},r_{i} (ti∈1,2,1≤li≤ri≤nt_i\in{1,2},1\le l_i\le r_i\le n) — the ii-th operation.

第一行包含两个整数 nn 和 mm(1≤n,m≤1051\le n,m\le 10^{5})—— 分别表示数组的元素个数和需要处理的操作个数。

第二行包含 nn 个整数 a1,a2,⋯ ,ana_{1},a_{2},\cdots ,a_{n}(1≤ai≤5⋅1061\le a_{i}\le 5\cdot 10^{6})—— 数组的元素。

接下来 mm 行,每行包含三个整数 ti,li,rit_{i},l_{i},r_{i}(ti∈{1,2},1≤li≤ri≤nt_i\in\{1,2\},1\le l_i\le r_i\le n)—— 第 ii 个操作。

输出格式

For each "2 ll rr", output the answer in an separate line.

对于每个“2 ll rr”,在单独一行中输出答案。

输入输出样例

  • 输入#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=0φ(φk−1(x)),k>0\varphi^k(x)=\begin{cases}x,&k=0\\\varphi(\varphi^{k-1}(x)),&k \gt 0\end{cases}.

At first, a=[8,1,6,3,7]a=[8,1,6,3,7].

To make sure a1=a2=a3=a4=a5a_1=a_2=a_3=a_4=a_5, we can change aa to a′=[φ3(8),φ0(1),φ2(6),φ2(3),φ3(7)]=[1,1,1,1,1]a'=[\varphi^3(8),\varphi^0(1),\varphi^2(6),\varphi^2(3),\varphi^3(7)]=[1,1,1,1,1], using 3+0+2+2+3=103+0+2+2+3=10 changes.

To make sure a3=a4a_3=a_4, we can change aa to a′=[φ0(8),φ0(1),φ1(6),φ1(3),φ0(7)]=[8,1,2,2,7]a'=[\varphi^0(8),\varphi^0(1),\varphi^1(6),\varphi^1(3),\varphi^0(7)]=[8,1,2,2,7], using 0+0+1+1+0=20+0+1+1+0=2 changes.

After "1 11 33", aa is changed to a=[φ1(8),φ1(1),φ1(6),φ0(3),φ0(7)]=[4,1,2,3,7]a=[\varphi^1(8),\varphi^1(1),\varphi^1(6),\varphi^0(3),\varphi^0(7)]=[4,1,2,3,7].

To make sure a3=a4a_3=a_4, we can change aa to a′=[φ0(4),φ0(1),φ0(2),φ1(3),φ0(7)]=[4,1,2,2,7]a'=[\varphi^0(4),\varphi^0(1),\varphi^0(2),\varphi^1(3),\varphi^0(7)]=[4,1,2,2,7], using 0+0+0+1+0=10+0+0+1+0=1 change.

记 φk(x)={x,k=0φ(φk−1(x)),k>0\varphi^k(x)=\begin{cases}x,&k=0\\\varphi(\varphi^{k-1}(x)),&k \gt 0\end{cases}。

初始时,a=[8,1,6,3,7]a=[8,1,6,3,7]。

为使 a1=a2=a3=a4=a5a_1=a_2=a_3=a_4=a_5,可将 aa 变为 a′=[φ3(8),φ0(1),φ2(6),φ2(3),φ3(7)]=[1,1,1,1,1]a'=[\varphi^3(8),\varphi^0(1),\varphi^2(6),\varphi^2(3),\varphi^3(7)]=[1,1,1,1,1],共需 3+0+2+2+3=103+0+2+2+3=10 次变换。

为使 a3=a4a_3=a_4,可将 aa 变为 a′=[φ0(8),φ0(1),φ1(6),φ1(3),φ0(7)]=[8,1,2,2,7]a'=[\varphi^0(8),\varphi^0(1),\varphi^1(6),\varphi^1(3),\varphi^0(7)]=[8,1,2,2,7],共需 0+0+1+1+0=20+0+1+1+0=2 次变换。

执行操作 “1 11 33” 后,aa 变为 a=[φ1(8),φ1(1),φ1(6),φ0(3),φ0(7)]=[4,1,2,3,7]a=[\varphi^1(8),\varphi^1(1),\varphi^1(6),\varphi^0(3),\varphi^0(7)]=[4,1,2,3,7]。

为使 a3=a4a_3=a_4,可将 aa 变为 a′=[φ0(4),φ0(1),φ0(2),φ1(3),φ0(7)]=[4,1,2,2,7]a'=[\varphi^0(4),\varphi^0(1),\varphi^0(2),\varphi^1(3),\varphi^0(7)]=[4,1,2,2,7],共需 0+0+0+1+0=10+0+0+1+0=1 次变换。

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

首页