A14787 | New Year Concert
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
New Year is just around the corner, which means that in School 179, preparations for the concert are in full swing.
There are $n$ classes in the school, numbered from $1$ to $n$ , the $i$ -th class has prepared a scene of length $a_i$ minutes.
As the main one responsible for holding the concert, Idnar knows that if a concert has $k$ scenes of lengths $b_1$ , $b_2$ , $\ldots$ , $b_k$ minutes, then the audience will get bored if there exist two integers $l$ and $r$ such that $1 \le l \le r \le k$ and $\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) = r - l + 1$ , where $\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r)$ is equal to the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the numbers $b_l$ , $b_{l + 1}$ , $\ldots$ , $b_{r - 1}$ , $b_r$ .
To avoid boring the audience, Idnar can ask any number of times (possibly zero) for the $t$ -th class ( $1 \le t \le k$ ) to make a new scene $d$ minutes in length, where $d$ can be any positive integer. Thus, after this operation, $b_t$ is equal to $d$ . Note that $t$ and $d$ can be different for each operation.
For a sequence of scene lengths $b_1$ , $b_2$ , $\ldots$ , $b_{k}$ , let $f(b)$ be the minimum number of classes Idnar has to ask to change their scene if he wants to avoid boring the audience.
Idnar hasn't decided which scenes will be allowed for the concert, so he wants to know the value of $f$ for each non-empty prefix of $a$ . In other words, Idnar wants to know the values of $f(a_1)$ , $f(a_1$ , $a_2)$ , $\ldots$ , $f(a_1$ , $a_2$ , $\ldots$ , $a_n)$ .
There are $n$ classes in the school, numbered from $1$ to $n$ , the $i$ -th class has prepared a scene of length $a_i$ minutes.
As the main one responsible for holding the concert, Idnar knows that if a concert has $k$ scenes of lengths $b_1$ , $b_2$ , $\ldots$ , $b_k$ minutes, then the audience will get bored if there exist two integers $l$ and $r$ such that $1 \le l \le r \le k$ and $\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) = r - l + 1$ , where $\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r)$ is equal to the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the numbers $b_l$ , $b_{l + 1}$ , $\ldots$ , $b_{r - 1}$ , $b_r$ .
To avoid boring the audience, Idnar can ask any number of times (possibly zero) for the $t$ -th class ( $1 \le t \le k$ ) to make a new scene $d$ minutes in length, where $d$ can be any positive integer. Thus, after this operation, $b_t$ is equal to $d$ . Note that $t$ and $d$ can be different for each operation.
For a sequence of scene lengths $b_1$ , $b_2$ , $\ldots$ , $b_{k}$ , let $f(b)$ be the minimum number of classes Idnar has to ask to change their scene if he wants to avoid boring the audience.
Idnar hasn't decided which scenes will be allowed for the concert, so he wants to know the value of $f$ for each non-empty prefix of $a$ . In other words, Idnar wants to know the values of $f(a_1)$ , $f(a_1$ , $a_2)$ , $\ldots$ , $f(a_1$ , $a_2$ , $\ldots$ , $a_n)$ .
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of classes in the school.
The second line contains $n$ positive integers $a_1$ , $a_2$ , $\ldots$ , $a_n$ ( $1 \le a_i \le 10^9$ ) — the lengths of the class scenes.
The second line contains $n$ positive integers $a_1$ , $a_2$ , $\ldots$ , $a_n$ ( $1 \le a_i \le 10^9$ ) — the lengths of the class scenes.
输出格式
Print a sequence of $n$ integers in a single line — $f(a_1)$ , $f(a_1$ , $a_2)$ , $\ldots$ , $f(a_1$ , $a_2$ , $\ldots$ , $a_n)$ .
输入输出样例
输入 #1
1 1
输出 #1
1
输入 #2
3 1 4 2
输出 #2
1 1 2
输入 #3
7 2 12 4 8 18 3 6
输出 #3
0 1 1 1 2 2 2
In the first test we can change $1$ to $2$ , so the answer is $1$ .
In the second test:
- $[1]$ can be changed into $[2]$ ,
- $[1, 4]$ can be changed into $[3, 4]$ ,
- $[1, 4, 2]$ can be changed into $[2, 3, 2]$ .
In the second test:
- $[1]$ can be changed into $[2]$ ,
- $[1, 4]$ can be changed into $[3, 4]$ ,
- $[1, 4, 2]$ can be changed into $[2, 3, 2]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted