A15866 | Li Hua and Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Li Hua wants to solve a problem about $\varphi$ — Euler's totient function. Please recall that $\varphi(x)=\sum\limits_{i=1}^x[\gcd(i,x)=1]$ . $^{\dagger,\ddagger}$
He has a sequence $a_1,a_2,\cdots,a_n$ and he wants to perform $m$ operations:
- "1 $l$ $r$ " ( $1\le l\le r\le n$ ) — for each $x\in[l,r]$ , change $a_x$ into $\varphi(a_x)$ .
- "2 $l$ $r$ " ( $1\le l\le r\le n$ ) — find out the minimum changes needed to make sure $a_l=a_{l+1}=\cdots=a_r$ . In each change, he chooses one $x\in[l,r]$ , change $a_x$ into $\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)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$ .
$^\ddagger$ The notation $[\textrm{cond}]$ equals $1$ if the condition $\textrm{cond}$ is true, and $0$ otherwise.
He has a sequence $a_1,a_2,\cdots,a_n$ and he wants to perform $m$ operations:
- "1 $l$ $r$ " ( $1\le l\le r\le n$ ) — for each $x\in[l,r]$ , change $a_x$ into $\varphi(a_x)$ .
- "2 $l$ $r$ " ( $1\le l\le r\le n$ ) — find out the minimum changes needed to make sure $a_l=a_{l+1}=\cdots=a_r$ . In each change, he chooses one $x\in[l,r]$ , change $a_x$ into $\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)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$ .
$^\ddagger$ The notation $[\textrm{cond}]$ equals $1$ if the condition $\textrm{cond}$ is true, and $0$ otherwise.
输入格式
The first line contains two integers $n$ and $m$ ( $1\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 $n$ integers $a_{1},a_{2},\cdots ,a_{n}$ ( $1\le a_{i}\le 5\cdot 10^{6}$ ) — the elements of the array.
Next $m$ lines, each line contains three integers $t_{i},l_{i},r_{i}$ ( $t_i\in\{1,2\},1\le l_i\le r_i\le n$ ) — the $i$ -th operation.
The second line contains $n$ integers $a_{1},a_{2},\cdots ,a_{n}$ ( $1\le a_{i}\le 5\cdot 10^{6}$ ) — the elements of the array.
Next $m$ lines, each line contains three integers $t_{i},l_{i},r_{i}$ ( $t_i\in\{1,2\},1\le l_i\le r_i\le n$ ) — the $i$ -th operation.
输出格式
For each "2 $l$ $r$ ", output the answer in an separate line.
输入输出样例
输入 #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 $\varphi^k(x)=\begin{cases}x,&k=0\\\varphi(\varphi^{k-1}(x)),&k > 0\end{cases}$ .
At first, $a=[8,1,6,3,7]$ .
To make sure $a_1=a_2=a_3=a_4=a_5$ , we can change $a$ to $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=10$ changes.
To make sure $a_3=a_4$ , we can change $a$ to $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=2$ changes.
After "1 $1$ $3$ ", $a$ is changed to $a=[\varphi^1(8),\varphi^1(1),\varphi^1(6),\varphi^0(3),\varphi^0(7)]=[4,1,2,3,7]$ .
To make sure $a_3=a_4$ , we can change $a$ to $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=1$ change.
At first, $a=[8,1,6,3,7]$ .
To make sure $a_1=a_2=a_3=a_4=a_5$ , we can change $a$ to $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=10$ changes.
To make sure $a_3=a_4$ , we can change $a$ to $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=2$ changes.
After "1 $1$ $3$ ", $a$ is changed to $a=[\varphi^1(8),\varphi^1(1),\varphi^1(6),\varphi^0(3),\varphi^0(7)]=[4,1,2,3,7]$ .
To make sure $a_3=a_4$ , we can change $a$ to $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=1$ change.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted