hdu 6085 (bitset区间取值)
来源:互联网 发布:java获取上月第一天 编辑:程序博客网 时间:2024/06/05 06:38
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 aren n children and m m kinds of candies. The i ith child has Ai Ai dollars and the unit price of the i ith kind of candy is Bi 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 has10 10 dollars and the unit price of his favorite candy is 4 4 dollars, then he will buy two candies and go home with 2 2 dollars left.
Now Yuta hasq q queries, each of them gives a number k k. For each query, Yuta wants to know the number of the pairs (i,j)(1≤i≤n,1≤j≤m) (i,j)(1≤i≤n,1≤j≤m) which satisfies if the i ith child’s favorite candy is the j jth kind, he will take k k dollars home.
To reduce the difficulty, Rikka just need to calculate the answer modulo2 2.
But It is still too difficult for Rikka. Can you help her?
There are
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
Now Yuta has
To reduce the difficulty, Rikka just need to calculate the answer modulo
But It is still too difficult for Rikka. Can you help her?
For each testcase, the first line contains three numbers
The second line contains
Then the fourth line contains
It is guaranteed that
15 5 51 2 3 4 51 2 3 4 50 1 2 3 4
00001
给出数组A和B,问多少对 A%B==ki。数据大小 5e4 考虑n^2/32*log 可以知道的是取模运算。
一个数%B 和%2B 结果相等,考虑到对ki的贡献,只有比ki大的B才会对ki有贡献,我们考虑遍历B.从大到小,然后不断更新B存在的位置(log),然后不断计算这样a%b(比当前b大)==ki的个数,这个只要用减法就可以做到,利用bitset的位运算,bx&(a>>i).count()&1,更方便快捷
#include <bits/stdc++.h>using namespace std;const int N = 50000+5;bitset<N> a,b,ans,bx;void solve(int x){bx.reset();for(int i=x;i>=0;i--){ans[i]=(bx&(a>>i)).count()&1;if(b[i]){for(int j=0;j<N;j+=i)bx.flip(j);}}}int main(){int t;scanf("%d",&t);while(t--){a.reset(),b.reset();int n,m,q,x,maxt=0;scanf("%d%d%d",&n,&m,&q);for(int i=1;i<=n;i++){scanf("%d",&x);a.set(x);}for(int i=1;i<=m;i++){scanf("%d",&x);b.set(x);maxt=max(x,maxt);}ans.reset();solve(maxt);while(q--){int x;scanf("%d",&x);puts(ans[x]?"1":"0");}}}
阅读全文
0 0
- hdu 6085 (bitset区间取值)
- hdu 6085(bitset)
- HDU 6085 Rikka with Candies 压位 bitset区间提取
- HDU 6085 Rikka with Candies (bitset)
- HDU 6085 Rikka with Candies(bitset)
- HDU 6085 Rikka with Candies (bitset)
- hdu 6085 bitset优化
- bitset(hdu 6085)
- HDU 6085 暴力bitset
- hdu 6085(bitset优化)
- HDU-5961(bitset)
- HDU 1006区间取交
- hdu 6119(区间重合处理)(尺取
- hdu 2051 Bitset (java)
- hdu 6085 Rikka with Candies(bitset容器)
- HDU 6085 Rikka with Candies(bitset操作+思路转化)
- hdu-Bitset
- Hdu 6085 Rikka with Candies【思维+Bitset】
- An=n的前n项和的前n项和
- java bean与xml相互转换
- Table的一些问题
- \r\n 回车和换行
- 【图像处理】MATLAB:彩色图像处理
- hdu 6085 (bitset区间取值)
- 评估目标之RMSE,MAP,NDCG
- PHP-成功配置imagick
- python问题请教:大佬们 AttributeError: 'int' object has no attribute 'save_bullet'
- codis集群部署实战
- ITIL运维服务管理的26个流程的密切关系说明
- Maven学习总结——理解maven的核心概念
- 《bt5从入门到精通》读书摘要
- PendingIntent使用填坑记