CF BUDDY
← Problems·

1632D · New Year Concert

2000 · binary search, data structures, greedy

Problem: 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 1lrk1 \le l \le r \le k and gcd(bl,bl+1,,br1,br)=rl+1\gcd(b_l, b_{l + 1}, \ldots, b_{r - 1}, b_r) = r - l + 1, where gcd(bl,bl+1,,br1,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, br1b_{r - 1}, brb_r.

To avoid boring the audience, Idnar can ask any number of times (possibly zero) for the tt-th class (1tk1 \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).

Input Format: The first line contains a single integer nn (1n21051 \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 (1ai1091 \le a_i \le 10^9) — the lengths of the class scenes.

Output Format: 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).

Note: 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].

Sample Cases

Case 1

Input

1
1

Output

1

Case 2

Input

3
1 4 2

Output

1 1 2

Case 3

Input

7
2 12 4 8 18 3 6

Output

0 1 1 1 2 2 2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback