CF1632D.New Year Concert

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

New Year is just around the corner, which means that in School 179, preparations for the concert are in full swing.

There are nn classes in the school, numbered from 11 to nn, the ii-th class has prepared a scene of length aia_i minutes.

As the main one responsible for holding the concert, Idnar knows that if a concert has kk scenes of lengths b1b_1, b2b_2, …\ldots, bkb_k minutes, then the audience will get bored if there exist two integers ll and rr such that 1≤l≤r≤k1 \le l \le r \le k and gcd⁡(bl,bl+1,…,br−1,br)=r−l+1\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) = r - l + 1, where gcd⁡(bl,bl+1,…,br−1,br)\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) is equal to the greatest common divisor (GCD) of the numbers blb_l, bl+1b_{l + 1}, …\ldots, br−1b_{r - 1}, brb_r.

To avoid boring the audience, Idnar can ask any number of times (possibly zero) for the tt-th class (1≤t≤k1 \le t \le k) to make a new scene dd minutes in length, where dd can be any positive integer. Thus, after this operation, btb_t is equal to dd. Note that tt and dd can be different for each operation.

For a sequence of scene lengths b1b_1, b2b_2, …\ldots, bkb_{k}, let f(b)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 ff for each non-empty prefix of aa. In other words, Idnar wants to know the values of f(a1)f(a_1), f(a1f(a_1,a2)a_2), …\ldots, f(a1f(a_1,a2a_2,…\ldots,an)a_n).

新年即将来临,这意味着学校179的音乐会筹备工作正在如火如荼地进行。

学校共有 nn 个班级,编号从 11 到 nn,其中第 ii 个班级准备了一个时长为 aia_i 分钟的节目。

作为音乐会的主要负责人,Idnar 知道:若一场音乐会包含 kk 个节目,其时长分别为 b1,b2,…,bkb_1, b_2, \ldots, b_k 分钟,则当存在两个整数 ll 和 rr 满足 1≤l≤r≤k1 \le l \le r \le k,且 gcd⁡(bl,bl+1,…,br−1,br)=r−l+1\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) = r - l + 1 时,观众将感到乏味。此处 gcd⁡(bl,bl+1,…,br−1,br)\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) 表示数列 bl,bl+1,…,br−1,brb_l, b_{l + 1}, \ldots, b_{r - 1}, b_r 的最大公约数(GCD)。

为避免观众感到乏味,Idnar 可以任意次数(包括零次)地要求第 tt 个班级(1≤t≤k1 \le t \le k)重新制作一个时长为 dd 分钟的新节目,其中 dd 可为任意正整数;执行该操作后,btb_t 即被替换为 dd。注意:每次操作中 tt 和 dd 均可不同。

对于节目时长序列 b1,b2,…,bkb_1, b_2, \ldots, b_k,记 f(b)f(b) 为 Idnar 为避免观众乏味而需请求更改节目的最少班级数量。

Idnar 尚未确定哪些节目将被允许登上音乐会舞台,因此他希望知道 ff 在 aa 的每个非空前缀上的取值。换言之,Idnar 希望获知以下各值:f(a1)f(a_1)、f(a1,a2)f(a_1,a_2)、…\ldots、f(a1,a2,…,an)f(a_1,a_2,\ldots,a_n)。

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of classes in the school.

The second line contains nn positive integers a1a_1, a2a_2, …\ldots, ana_n (1≤ai≤1091 \le a_i \le 10^9) — the lengths of the class scenes.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示学校中班级的数量。

第二行包含 nn 个正整数 a1a_1, a2a_2, …\ldots, ana_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示各班级场景的长度。

输出格式

Print a sequence of nn integers in a single line — f(a1)f(a_1), f(a1f(a_1,a2)a_2), …\ldots, f(a1f(a_1,a2a_2,…\ldots,an)a_n).

在一行中输出 nn 个整数的序列:f(a1)f(a_1)、f(a1,a2)f(a_1,a_2)、…\ldots、f(a1,a2,…,an)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 11 to 22, so the answer is 11.

In the second test:

  • [1][1] can be changed into [2][2],
  • [1,4][1, 4] can be changed into [3,4][3, 4],
  • [1,4,2][1, 4, 2] can be changed into [2,3,2][2, 3, 2].

在第一个测试用例中,我们可以将 11 改为 22,因此答案是 11。

在第二个测试用例中:

  • [1][1] 可以改为 [2][2],
  • [1,4][1, 4] 可以改为 [3,4][3, 4],
  • [1,4,2][1, 4, 2] 可以改为 [2,3,2][2, 3, 2]。

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

首页