luogu#P3536. [POI2012] BON-Vouchers

[POI2012] BON-Vouchers

题目描述

The candy shop owned by Byteasar sells delicious caramel candy.

For every positive integer cc there is exactly one package that contains cc candies; currently no new deliveries are expected.

To encourage customers to buy the sweets, Byteasar has planted mm vouchers for an annual supply of chocolate into some packages, making sure to put at most one voucher in each package.

The carnival starts next week in Byteburg, and it will last nn days; on the kk-th day of the carnival a party with aka_k guests will be held.

Byteasar is confident that on the kk-th day's morning each of those guests is going to buy, in his own store, the smallest package of candy available whose content can be equally distributed between the party guests. For example, if n=2n=2, a1=4a_1=4, a2=2a_2=2, then on the first day of the carnival he expects to sell the packages containing four, eight, twelve, and sixteen candies, selling those with two and six candies on the second day.

Now he is wondering which customers will end up with the packages holding the vouchers.

He has asked you to write a program that will determine this for him.

定义n个数为幸运数字,一共有n批人,设第i批人有x个,则它们会依次取走余下的x的倍数中最小的x个,问哪些人去走了幸运数字

输入格式

On the first line of the standard input there is a single integer mm (1m1 000 0001\le m\le 1\ 000\ 000) that denotes the number of vouchers.

The kk-th of the mm lines that follow holds an integer bkb_k (1bk1 000 0001\le b_k\le 1\ 000\ 000)denoting the size (i.e., the number of candies inside) of a package in which Byteasar has placed the kk-th voucher.

These numbers are given in an increasing order.

Then the next line contains a single integer nn (1n1 000 0001\le n\le 1\ 000\ 000) that denotes the number of carnival days.

The kk-th of the nn lines that follow holds an integer aka_k(1ak1 000 0001\le a_k\le 1\ 000\ 000)denoting the number of guests attending the kk-th party.

You may assume that in tests worth at least 50% of the total points none of the numbers given on the input exceeds 5 0005\ 000.

输出格式

In the first line of the standard output your program should print an integer zz - the number of packages with vouchers sold.

The following zz lines should specify the numbers of those customers who bought a package with a voucher, in an increasing order.

The customers are numbered from 11 in the order of their purchases.

题目大意

题目描述

Byteasar 经营着一家焦糖店。

对于所有正整数 cc,Byteasar 都有且仅有一个装有 cc 个糖果的包裹。

Byteasar 准备了 mm 张代金券,并在装有 bib_i 个糖果的包裹里分别放入一张。

现在共有 nn 批顾客,第 ii 批客人有 aia_i 人,且每名顾客会买走装有最少糖果的包裹,满足这些糖果可平均分给这一批的 aia_i 个人。例如,若 n=2,a1=4,a2=8n = 2, a_1 = 4, a_2 = 8,则第一批顾客买走的糖果数量分别为 4,8,12,164, 8, 12, 16,第二批顾客买走的糖果数量分别为 2,62, 6

将所有顾客按顺序从 11 开始编号,Byteasar 想知道取走代金券的顾客数量和各自的编号。

输入输出格式

输入格式

第一行输入一个整数 mm (1m1 000 0001 \le m \le 1\ 000\ 000),表示代金券总数。

接下来 mm 行,输入 mm 个整数 b1,b2,,bmb_1,b_2,\cdots, b_m (1bi1 000 0001 \le b_i \le 1\ 000\ 000),分别代表放入代金券的包裹装有的糖果数量,保证 bib_i 单调递增。

接下来输入一个整数 nn (1n1 000 0001 \le n \le 1\ 000\ 000),表示共有 nn 批顾客。

接下来 nn 行,输入 nn 个整数 a1,a2,,ana_1,a_2,\cdots, a_n (1ai1 000 0001 \le a_i \le 1\ 000\ 000),分别代表每批顾客的人数。

对于不少于 50%50\% 的数据,保证输入的所有数字不超过 5 0005\ 000

输出格式

第一行一个整数 zz,代表获得代金券的顾客数量。

接下来 zz 行每行一个整数,从小到大输出获得代金券的顾客编号。

4
1
6
8
16
3
4
2
4
3
2
4
6