Rikka with Candies
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1389 Accepted Submission(s): 606
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
i th child has
Ai dollars and the unit price of the
i th 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
10 dollars 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
i th child’s favorite candy is the
j th 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
Source
2017 Multi-University Training Contest - Team 5
Recommend
liuyiding | We have carefully selected several similar problems for you: 6107 6106 6105 6104 6103
Statistic | Submit | Discuss | Note
题解:
考虑枚举k,此时只有bj>k,ai>=k,才可能满足ai%bj=k
bbi={i的>k的因子属于b[1...m]的个数}
此时余数为k的情况数=∑ni=1bbai−k
考虑用bitset存放a,bitsetA>>k等价于a数组全部元素减去k,丢弃<0的元素
bitsetBB[i]=bbi & 1
ans[k]=(bitsetA>>k) & bitsetBB.count() & 1
求解bb,对每个bi,枚举其倍数,O(N∑1bi)
最坏情况下变为N∗调和级数=O(N∑Ni=11N)约等于O(N∗ln(N+1))
枚举k,对bitsetA和bitsetBB进行and操作O(N232)
所以复杂度大概O(N232+N∗ln(N+1))
#include
#include
#include
#include
#include
#include
#include
#include