Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
There are n children and m kinds of candies. The ith child has Ai dollars and the unit price of the ith kind of candy is Bi. The amount of each kind is infinity. 
Each child has his favorite candy, so he will buy this kind of candies as much as possible and will not buy any candies of other kinds. For example, if this child has 10dollars and the unit price of his favorite candy is 4 dollars, then he will buy two candies and go home with 2 dollars left.
Now Yuta has q queries, each of them gives a number k. For each query, Yuta wants to know the number of the pairs (i,j)(1≤i≤n,1≤j≤m) which satisfies if the ith child’s favorite candy is the jth kind, he will take k dollars home.
To reduce the difficulty, Rikka just need to calculate the answer modulo 2.
But It is still too difficult for Rikka. Can you help her?
 
Input
The first line contains a number t(1≤t≤5), the number of the testcases. 
For each testcase, the first line contains three numbers n,m,q(1≤n,m,q≤50000). 
The second line contains n numbers Ai(1≤Ai≤50000) and the third line contains m numbers Bi(1≤Bi≤50000).
Then the fourth line contains q numbers ki(0≤ki<maxBi) , which describes the queries.
It is guaranteed that Ai≠Aj,Bi≠Bj for all i≠j.
Output
For each query, print a single line with a single 01 digit -- the answer.
Sample Input
1
5 5 5
1 2 3 4 5
1 2 3 4 5
0 1 2 3 4
Sample Output
0
0
0
0
1
 

给你一个长度为n的a数组,m的b数组,再给你q个询问,每个询问为一个k,问在a b 数组中满足 a[i]%b[j]=k的i,j有多少对,答案对2取模.保证a  b 中的数组不会重复.

答案对2取模的话就提示你在用bitset来加速处理.我们先对询问排一个序,b数组排一个序.我们先用一个aa的bitset存下a数组中出现的数字

bb存b[j]的倍数,因为如果[i]%b[j]=k,那么b[j]应该是>k的.然后对已每一个询问不断更新bb也就是不断加上下一个较小的b[j]

对于每一个询问的结果我们只需要(((aa>>q[i].k)&bb).count())&1;这样就是答案了

代码如下:

 #include <bits/stdc++.h>
using namespace std;
const int BufferSize=<<;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=,f=;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-;
for(;isdigit(c);c=Getchar()) x=x*+c-'';
return x*f;
}
inline void write(int x)
{
if(x>=)write(x/);
putchar(x%+'');
}
const int maxn = ;
int n,m,qu;
int a[maxn],b[maxn];
int ret[maxn];
bitset<maxn> aa,bb;
struct query
{
int k,id;
}q[maxn];
bool cmp (query q1,query q2)
{
return q1.k>q2.k;
}
int main()
{
//freopen("de.txt","r",stdin);
int T;
T=read();
while (T--){
n=read(),m=read(),qu=read();
aa.reset();
bb.reset();
for (int i=;i<=n;++i){
a[i]=read();
aa.set(a[i]);
}
for (int i=;i<=m;++i)
b[i]=read();
sort(b+,b++m);
for (int i=;i<=qu;++i)
q[i].k=read(),q[i].id=i,ret[i]=;
sort(q+,qu++q,cmp);
int now = m+;
for (int i=;i<=qu;++i){
while (now->=&&b[now-]>q[i].k){
now--;
for (int j=;j<=;j+=b[now])//枚举b[now]的倍数,从0开始
bb[j]=bb[j]^;
}
ret[q[i].id] =(((aa>>q[i].k)&bb).count())&;
}
for (int i=;i<=qu;++i)
write(ret[i]),putchar();
}
return ;
}

加上快速读入3400ms左右,时限是3500...

hdu 6085 Rikka with Candies (set计数)的更多相关文章

  1. HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5

    看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...

  2. 2017ACM暑期多校联合训练 - Team 5 1001 HDU 6085 Rikka with Candies (模拟)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  3. HDU 6085 Rikka with Candies(bitset)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6085 [题目大意] 给出一个数组a一个数组b,以及询问数组c, 问对于每个c有多少对a%b=c,答 ...

  4. 2017多校第5场 HDU 6085 Rikka with Candies bitset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6085 题意:存在两个长度为n,m的数组A,B.有q个询问,每个询问有一个数字k,可以得到Ai%Bj=k ...

  5. hdu 6092 Rikka with Subset (集合计数,01背包)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  6. HDU 6415 Rikka with Nash Equilibrium (计数DP)

    题意:给两个整数n,m,让你使用 1 ~ n*m的所有数,构造一个矩阵n*m的矩阵,此矩阵满足:只有一个元素在它的此行和此列中都是最大的,求有多种方式. 析:根据题意,可以知道那个元素一定是 n * ...

  7. HDU 5831 Rikka with Parenthesis II(六花与括号II)

    31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  8. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  9. HDU 6085 bitset

    Rikka with Candies Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

随机推荐

  1. Linux进程管理工具vmstat,iostat,pmap

    一查看内存的工具——vmstat (一)vmstat的介绍 vmstat vmstat是Virtual Memory Statistics(虚拟内存统计)的缩写 利用vmstat命令可以对操作系统的报 ...

  2. JAVA(JDK,JRE)更改目录安装及环境变量配置

    重温一下 JAVA(JDK,JRE)更改目录安装及环境变量配置 https://jingyan.baidu.com/article/e2284b2b5b7ae5e2e7118d11.html 备注:随 ...

  3. python 对 excel 的操作

    参考:https://www.php.cn/python-tutorials-422881.html  或 https://blog.51cto.com/wangfeng7399/2339556(使用 ...

  4. Borůvka (Sollin) 算法求 MST 最小生成树

    基本思路: 用定点数组记录每个子树的最近邻居. 对于每一条边进行处理: 如果这条边连成的两个顶点同属于一个集合,则不处理,否则检测这条边连接的两个子树,如果是连接这两个子树的最小边,则更新 (合并). ...

  5. [杂题]:group(状压DP+轮廓线)

    题目描述 $pure$在玩一个战略类游戏.现在有一个士兵方阵,每行有若干士兵,每个士兵属于某个兵种.行的顺序不可改变,且每一行中士兵的顺序也不可改变.但由于每一行都有$C$个位置($C$不小于任一行的 ...

  6. Autoresize UIView to fit subviews

    @interface UIView (resizeToFit) -(void)resizeToFitSubviews; -(void)resizeHightToFitSubviews; -(void) ...

  7. css3D动画

    css3D动画 前言 最近玩了玩用css来构建3D效果,写了几个demo,所以博客总结一下. 在阅读这篇博客之前,请先自行了解一下css 3D的属性,例如:transform-style,transf ...

  8. 安装maven之后,cmd提示mvn不是内部命令的解决办法

    1.maven的安装教程 下载地址为:http://maven.apache.org/download.cgi 进入此页面之后 点击下载,然后解压,我把目录名改为maven,目录结构如下图所示 下面我 ...

  9. 重新认识new

    前言 感谢大佬:https://www.cnblogs.com/luxiaoxun/archive/2012/08/10/2631812.html www.cplusplus.com 因为这段时间在重 ...

  10. laravel 向多视图及所有视图传递数据变量

    向单个视图传递变量 1.使用with()方法 : view('user.lists')->with('title',$title); 2.直接view()传参: view('user.lists ...