A9587 | Ant colony
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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, \ldots, 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.
The second line contains $n$ integers $s_1, s_2, \ldots, 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.
输出格式
Print to the standard output $t$ lines. The $i$-th line contains number of ants that Mole eats from the segment $[l_i, r_i]$.
输入输出样例
输入 #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]$, so ant number $1$ is freed. Mole eats the ants $2, 3, 4, 5$.
In the second test case battle points are $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]$, so ants number $3$ and $5$ are freed. Mole eats only the ant $4$.
In the fourth test case battle points are $v = [0, 1]$, so ant number $5$ is freed. Mole eats the ant $4$.
In the second test case battle points are $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]$, so ants number $3$ and $5$ are freed. Mole eats only the ant $4$.
In the fourth test case battle points are $v = [0, 1]$, so ant number $5$ is freed. Mole eats the ant $4$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted