[BZOJ2793] [Poi2012] Vouchers

Source: Internet
Author: User

2793: [poi2012]vouchers time limit:20 Sec Memory limit:64 MB
submit:316 solved:148
[Submit] [Status] [Discuss] Description


Considering the set of positive integers, there are now n groups of people to take the number, assuming that group I to x people, they each take the number of x must be a multiple, and is the smallest remaining x.
The number of M in a positive integer is labeled as a lucky number, asking who gets the lucky number.

Input


The first line is a positive integer m (m<=1,000,000), and the following m line has a positive integer x (x<=1,000,000) for each line, indicating that X is a lucky number.
The next line is a positive integer n (n<=1,000,000), and the following n lines a positive integer x (x<=1,000,000) for each line, indicating that this group comes in X person.

Output

The first line outputs a non-negative integer k, which indicates that the K-person has taken the lucky number, and the following K-line represents the number of the person who took the lucky number, which is numbered starting from 1 in the order in which they came.

Sample Input4
1
6
8
16
3
4
2
4

Sample Output3
2
4
6
HINT



Hint

A total of 10 people, the number they take away is 4 8 12 16 2 6 20 24 28 32.

2nd, 4, 6 people take the lucky number 8, 16, 6.


(don't think about it too hard, actually it's very water)


Source

Acknowledgement Oimaster

[Submit] [Status] [Discuss]


Maintain a next array for each x, representing the position of the next X, and then brute force processing.

Briefly estimate the upper limit complexity of $\sum\limits_{i=1}^n\frac mi=o (MLOGN) where m=\max{a_i}$

But it's definitely not going to be that complicated.

1#include <cstdio>2#include <algorithm>3 #defineN 10000104 #definell Long Long5 using namespacestd;6 intN,next[n],maxn,tot,m,a[n];7 ll Ans[n],sum,vis[n];8 intMain ()9 {Tenscanf"%d",&n); One      for(intI=1; i<=n;i++) Ascanf"%d", &a[i]), maxn=Max (A[I],MAXN); -scanf"%d",&m); -      while(m--) the     { -         intx; -scanf"%d",&x); -ll now=sum;sum+=x; +          for(inti=x;i&&next[x]+x<=MAXN;) -         if(!vis[next[x]+=x]) +vis[next[x]]=++now,i--; A     } at      for(intI=1; i<=n;i++) -     if(Vis[a[i]]) -ans[++tot]=Vis[a[i]]; -Sort (ans+1, ans+tot+1); -printf"%d\n", tot); -      for(intI=1; i<=tot;i++) inprintf"%lld\n", Ans[i]); -}
View Code

[BZOJ2793] [Poi2012] Vouchers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.