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. 媲美5G的Wifi网速、“备战”资产一键领……揭秘双11小二背后的保障力量

    如今,双11不光是购物狂欢节,更是对技术的一次“大考”,对于阿里巴巴企业内部运营的基础保障技术而言,亦是如此. 回溯双11历史,这背后也经历过“小米加步枪”的阶段:作战室从随处是网线,交换机放地上的“ ...

  2. python打印9宫格,25宫格等奇数格,且横竖斜相加和相等

    代码如下: #!/usr/bin/env python3#-*- coding:utf-8 -*-num = int(input('请输入一个奇数:'))# 定义一个长为num的列表high = [[ ...

  3. Maven之搭建本地私服(nexus)仓库

    摘要:现在越来越多的项目都在使用Maven管理项目,尤其是在大型的项目团队中使用Maven能带来更加多的好处,私服的好处我相信大家都明白,在这里我就不多说了,它最重要的作用就是可以让项目团队成员更加方 ...

  4. css控制显示超出多少行以后开始出现省略号的写法

    display: -webkit-box; display: -moz-box; text-overflow: -o-ellipsis-lastline; text-overflow: ellipsi ...

  5. java并发编程笔记(六)——AQS

    java并发编程笔记(六)--AQS 使用了Node实现FIFO(first in first out)队列,可以用于构建锁或者其他同步装置的基础框架 利用了一个int类型表示状态 使用方法是继承 子 ...

  6. stl源码为什么要大量使用typedef?

    SGI源码download,<stl源码剖析>里展示了vector的部分源码: template <class T, class Alloc = alloc> class ve ...

  7. appium常见问题07_appium输入中文无效

    前几天在appium android自动化测试过程中,使用send_keys()输入中文,发现只能输入字母和数字,输入中文无反应. 大家是否同样遇到过该问题,当大家同样遇到该问题时,在配置参数desi ...

  8. 《单词的减法》state1~state17(第三遍学习记录)

    2016.05.24 state 8 curse/curve dedication 多用于奉献和献身 disastrous disruptive distract state 9 domestic/d ...

  9. [题解]Magic Line-计算几何(2019牛客多校第三场H题)

    题目链接:https://ac.nowcoder.com/acm/contest/883/H 题意: 给你偶数个点的坐标,找出一条直线将这n个点分成数量相等的两部分 并在这条直线上取不同的两个点,表示 ...

  10. python读取mysql返回json

    python内部是以tuple格式存储的关系型数据库的查询结果,在实际的使用过程中可能需要转换成list或者dict,json等格式.在这里讲解如何将查询的结果转成json字符串.这里需要导入nump ...