CF547C.Mike and Foam

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has a__i milliliters of foam on it.

Maxim is Mike's boss. Today he told Mike to perform q queries. Initially the shelf is empty. In each request, Maxim gives him a number x. If beer number x is already in the shelf, then Mike should remove it from the shelf, otherwise he should put it in the shelf.

After each query, Mike should tell him the score of the shelf. Bears are geeks. So they think that the score of a shelf is the number of pairs (i, j) of glasses in the shelf such that i < j and where is the greatest common divisor of numbers a and b.

Mike is tired. So he asked you to help him in performing these requests.

迈克是里科酒吧的一名调酒师。在里科酒吧,他们将啤酒杯放置在一个特殊的架子上。里科酒吧共有 nn 种啤酒,编号从 11 到 nn。第 ii 种啤酒的泡沫量为 aia_i 毫升。

马克西姆是迈克的老板。今天他让迈克执行 qq 个查询。初始时,架子为空。在每次查询中,马克西姆给迈克一个数字 xx:若编号为 xx 的啤酒杯已在架子上,则迈克需将其取下;否则,迈克需将其放上架子。

每次查询后,迈克需向马克西姆报告该架子的“得分”。熊族是极客,因此他们认为架子的得分等于架子上所有满足 i<ji < j 且 的啤酒杯对 (i, j)(i,\,j) 的数量,其中 表示整数 aa 与 bb 的最大公约数。

迈克很疲惫,因此他请你帮忙完成这些查询。

输入格式

The first line of input contains numbers n and q (1 ≤ n, q ≤ 2 × 105), the number of different kinds of beer and number of queries.

The next line contains n space separated integers, _a_1, _a_2, ... , a__n (1 ≤ a__i ≤ 5 × 105), the height of foam in top of each kind of beer.

The next q lines contain the queries. Each query consists of a single integer integer x (1 ≤ x ≤ n), the index of a beer that should be added or removed from the shelf.

输入的第一行包含两个整数 nn 和 qq(1 ≤ n, q ≤ 2 × 1051 \le n, q \le 2 \times 10^5),分别表示啤酒的种类数和查询次数。

第二行包含 nn 个用空格分隔的整数 a1, a2, …, ana_1, a_2, \dots, a_n(1 ≤ ai ≤ 5 × 1051 \le a_i \le 5 \times 10^5),表示每种啤酒顶部泡沫的高度。

接下来的 qq 行为查询。每次查询包含一个整数 xx(1 ≤ x ≤ n1 \le x \le n),表示应被添加或从货架上移除的啤酒的索引。

输出格式

For each query, print the answer for that query in one line.

对于每个查询,在一行中输出该查询的答案。

输入输出样例

  • 输入#1

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

    输出#1

    0
    1
    3
    5
    6
    2

输入解题思路,AI测评打分。不知道怎么写?

首页