首页 > 其他 > 详细

codeforces CF474F Ant colony 线段树 区间gcd

时间:2018-09-19 21:04:02      阅读:205      评论:0      收藏:0      [点我收藏+]

$ \Rightarrow $ 戳我进CF原题

F. Ant colony


time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Mole is hungry again. He found one ant colony, consisting of $ n $ ants, ordered in a row.
Each ant $ i (1?≤?i?≤?n) $ has a strength $ 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 $ and $ r (1?≤?l?≤?r?≤?n) $ and each pair of ants with indices between $ l $ and $ r $ (inclusively) will fight.
When two ants $ i $ and $ j $ fight, ant $ i $ gets one battle point only if $ s_i $ divides $ s_j $
(also, ant j gets one battle point only if $ s_j $ divides $ s_i $ ).

After all fights have been finished, Mole makes the ranking.
An ant $ i $ , with $ v_i $ battle points obtained, is going to be freed only if $ 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 $ segments $ [l_i,?r_i] $ and asks for each of them how many ants is he going to eat if those ants fight.

Input

The first line contains one integer $ n (1?≤?n?≤?10^5) $ , the size of the ant colony.
The second line contains n integers $ s_1,?s_2,?...,?s_n (1?≤?s_i?≤?10^9) $ , the strengths of the ants.
The third line contains one integer $ t (1?≤?t?≤?10^5) $ , the number of test cases.
Each of the next $ t $ lines contains two integers $ l_i $ and $ r_i (1?≤?l_i?≤?r_i?≤?n) $ , describing one query.

codeforces CF474F Ant colony 线段树 区间gcd

原文:https://www.cnblogs.com/PotremZ/p/CF474F.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!