hdu 6085 Rikka with Candies (set计数)
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?
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.
给你一个长度为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计数)的更多相关文章
- HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5
看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...
- 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 ...
- HDU 6085 Rikka with Candies(bitset)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6085 [题目大意] 给出一个数组a一个数组b,以及询问数组c, 问对于每个c有多少对a%b=c,答 ...
- 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 ...
- hdu 6092 Rikka with Subset (集合计数,01背包)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6415 Rikka with Nash Equilibrium (计数DP)
题意:给两个整数n,m,让你使用 1 ~ n*m的所有数,构造一个矩阵n*m的矩阵,此矩阵满足:只有一个元素在它的此行和此列中都是最大的,求有多种方式. 析:根据题意,可以知道那个元素一定是 n * ...
- HDU 5831 Rikka with Parenthesis II(六花与括号II)
31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- HDU 6085 bitset
Rikka with Candies Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
随机推荐
- 浅析弹性公网IP付费模式和短时升配功能介绍
弹性公网IP付费模式对比 弹性公网IP(EIP),有两种付费方式.一种是预付费,一种是后付费.对于预付费弹性公网IP而言,最大的优点就是带宽费用便宜,相对于后付费有比较大的优惠. 例如,杭州地域6 ...
- 关于iphone设置显示模式为标准模式和放大模式时的区别
参考来自:https://www.jianshu.com/p/5f61d914114b CGFloat scale = [[UIScreen mainScreen] scale]; CGFloat n ...
- SpringMvc处理模型数据(也就是从数据库中查询出来的数据放到请求域中)
这讲的是从数据库中查询到的数据,存放到请求域中.然后页面上直接可以从请求域中获取值. 有4种方式: 1):ModelAndView 是作为一个对象. /** * 目标方法的返回值可以是 Model ...
- 二叉查找树BST
每棵子树头节点的值都比各自左子树上所有节点值要大,也都比各自右子树上所有节点值要小. 二叉查找树的中序遍历序列一定是从小到大排列的. 一个节点的后继节点是指,这个节点在中序遍历序列中的下一个节点.相应 ...
- “pod repo push”遇到的2个问题的解决方案
podspec文件push到遇到的第一个问题,将进行记录,主要是参考了下面大神的解决方案,主要是为了方便学习和记录 第一个问题: xcrun: error: invalid active develo ...
- leetcode-解题记录 884. 两句话中的不常见单词
题目 给定两个句子 A 和 B . (句子是一串由空格分隔的单词.每个单词仅由小写字母组成.) 如果一个单词在其中一个句子中只出现一次,在另一个句子中却没有出现,那么这个单词就是不常见的. 返回所有不 ...
- kubernetes安装部署
1.根据系统内核情况,选择对应的ali云上的镜像,作为仓库的路径指向来配置k8s https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes- ...
- 8条关于Web前端性能的优化建议
一般网站优化都是优化后台,如接口的响应时间.SQL优化.后台代码性能优化.服务器优化等.高并发情况下,对前端web优化也是非常重要的. 下面说说几种常见的优化措施. 1.HTML CSS JS位置 一 ...
- 解决text-align: justify;浏览器、安卓手机不兼容问题
1.兼容PC端浏览器 .h_text{ text-align:justify; text-justify:inter-ideograph;width:200px;} .span_hid{ displa ...
- webstorm的下载、破解、与汉化
其实很简单的事情,都被我弄复杂了倒腾了很久,特做个记录. 说明前提,版本为 webstorm 2018.1.4 一.下载webstorom 下载地址:当然去官网啊 https://www.jetbr ...