#P4899. Ant colony

    ID: 2536 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>数据结构线段树其他离散化CodeForces

Ant colony

Ant colony

题面翻译

给出一个长度为 nn 的序列 ssqq 组询问。

每次给定区间 [l,r][l,r]

如果 i,j[l,r]i,j \in [l,r]sisjs_i|s_jii 得一分。

问有多少个没有得到满分,即 rlr-l

题目描述

Mole is hungry again. He found one ant colony, consisting of n n ants, ordered in a row. Each ant i i ( 1<=i<=n 1<=i<=n ) has a strength si s_{i} .

In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l l and r r ( 1<=l<=r<=n 1<=l<=r<=n ) and each pair of ants with indices between l l and r r (inclusively) will fight. When two ants i i and j j fight, ant i i gets one battle point only if si s_{i} divides sj s_{j} (also, ant j j gets one battle point only if sj s_{j} divides si s_{i} ).

After all fights have been finished, Mole makes the ranking. An ant i i , with vi v_{i} battle points obtained, is going to be freed only if vi=rl v_{i}=r-l , or in other words only if it took a point in every fight it participated. After that, Mole eats the rest of the ants. Note that there can be many ants freed or even none.

In order to choose the best sequence, Mole gives you t t segments [li,ri] [l_{i},r_{i}] and asks for each of them how many ants is he going to eat if those ants fight.

输入格式

The first line contains one integer nn (1n1051 ≤ n ≤ 10^5), the size of the ant colony.

The second line contains nn integers s1,s2,,sns_1, s_2, \ldots, s_n (1si1091 ≤ s_i ≤ 10^9), the strengths of the ants.

The third line contains one integer tt (1t1051 ≤ t ≤ 10^5), the number of test cases.

Each of the next tt lines contains two integers lil_i and rir_i (1lirin1 ≤ l_i ≤ r_i ≤ n), describing one query.

输出格式

Print to the standard output tt lines. The ii-th line contains number of ants that Mole eats from the segment [li,ri][l_i, r_i].

样例 #1

样例输入 #1

5
1 3 2 4 2
4
1 5
2 5
3 5
4 5

样例输出 #1

4
4
1
1

提示

In the first test battle points for each ant are v=[4,0,2,0,2]v = [4, 0, 2, 0, 2], so ant number 11 is freed. Mole eats the ants 2,3,4,52, 3, 4, 5.

In the second test case battle points are v=[0,2,0,2]v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole.

In the third test case battle points are v=[2,0,2]v = [2, 0, 2], so ants number 33 and 55 are freed. Mole eats only the ant 44.

In the fourth test case battle points are v=[0,1]v = [0, 1], so ant number 55 is freed. Mole eats the ant 44.