首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >BZOJ 2793: [Poi2012]Vouchers(调和级数)

BZOJ 2793: [Poi2012]Vouchers(调和级数)

作者头像
attack
发布2018-04-10 17:11:27
1K0
发布2018-04-10 17:11:27
举报

Description

考虑正整数集合,现在有n组人依次来取数,假设第i组来了x人,他们每个取的数一定是x的倍数,并且是还剩下的最小的x个。 正整数中有m个数被标成了幸运数,问有哪些人取到了幸运数。

Input

第一行一个正整数m (m<=1,000,000),下面m行每行一个正整数x (x<=1,000,000),表示x是一个幸运数。 接下来一行一个正整数n (n<=1,000,000),下面n行每行一个正整数x (x<=1,000,000),表示这一组来了x个人。

Output

第一行输出一个非负整数k,表示k个人取到了幸运数,下面k行依次表示取到幸运数的人的编号,人按照来的顺序从1开始编号。

Sample Input

4 1 6 8 16 3 4 2 4

Sample Output

3 2 4 6

HINT

Hint 总共来了10个人,他们取走的数依次是4 8 12 16 2 6 20 24 28 32。 第2、4、6个人取到的是幸运数8、16、6。

(别把这题想太难,其实很水的)

Source

鸣谢Oimaster

我真傻,真的。

单知道这题是个大暴力就不用花半个小时去推式子。。。

还是太菜了QWQ....

我们用have[x]表示x的倍数已经枚举到了多少

然后对于每个询问暴力枚举就可以了。。起点是have[x]+x

时间复杂度

\dfrac {n}{1}+\dfrac {n}{2}+\ldots +\dfrac {n}{n}=n\log n

// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#define int long long 
//#define getchar() (S == T && (T = (S = BB) + fread(BB, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
//char BB[1 << 15], *S = BB, *T = BB;
using namespace std;
const int MAXN=1e6+10;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int have[MAXN],take[MAXN],a[MAXN],limit=0;
int ans[MAXN],cnt=0;
main()
{
    #ifdef WIN32
    freopen("a.in","r",stdin);
    #else
    #endif
    int N=read();
    for(int i=1;i<=N;i++) 
    {
        int x=read();
        limit=max(limit,x);
        a[x]=1;
    }
    int M=read();
    int now=0;
    while(M--)
    {
        int x=read(),t=x;
        for(int i=have[x]+x;i<=limit;i+=x)
        {
            if(!take[i])
            {
                now++;t--;
                take[i]=1;
                if(a[i]) ans[++cnt]=now;
            }
            have[x]=i;
            if(t==0) break;
        }
        now+=t;
    }
    printf("%lld\n",cnt);
    for(int i=1;i<=cnt;i++)
        printf("%lld\n",ans[i]);
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-02-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
  • Sample Input
  • Sample Output
  • HINT
  • Source
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档