CF301D.Yaroslav and Divisors
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yaroslav has an array p = _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ n), consisting of n distinct integers. Also, he has m queries:
- Query number i is represented as a pair of integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ n).
- The answer to the query l__i, r__i is the number of pairs of integers q, w (l__i ≤ q, w ≤ r__i) such that p__q is the divisor of p__w.
Help Yaroslav, answer all his queries.
亚罗斯拉夫有一个数组 p=p1,p2,…,pn(其中 1≤pi≤n),该数组由 n 个互不相同的整数组成。此外,他还有 m 个查询:
- 第 i 个查询以一对整数 li,ri 表示(满足 1≤li≤ri≤n)。
- 查询 li,ri 的答案是满足如下条件的整数对 (q,w) 的数量:li≤q,w≤ri,且 pq 是 pw 的约数。
请帮助亚罗斯拉夫回答所有查询。
输入格式
The first line contains the integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n distinct integers _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ n). The following m lines contain Yaroslav's queries. The i-th line contains integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ n).
第一行包含两个整数 n 和 m(1≤n,m≤2⋅105)。第二行包含 n 个互不相同的整数 p1,p2,…,pn(1≤pi≤n)。接下来的 m 行描述雅罗斯拉夫的查询。第 i 行包含两个整数 li,ri(1≤li≤ri≤n)。
输出格式
Print m integers — the answers to Yaroslav's queries in the order they appear in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出 m 个整数——即按输入中出现的顺序给出的 Yaroslav 的查询的答案。
请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
1 1 1 1 1
输出#1
1
输入#2
10 9 1 2 3 4 5 6 7 8 9 10 1 10 2 9 3 8 4 7 5 6 2 2 9 10 5 10 4 10
输出#2
27 14 8 4 2 1 2 7 9
输入解题思路,AI测评打分。不知道怎么写?