天天看點

【bitset騷操作】HDU - 6085 A - Rikka with Candies

A - Rikka with Candies

 HDU - 6085

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 nn children and mm kinds of candies. The iith child has AiAidollars and the unit price of the iith kind of candy is BiBi. 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 qq queries, each of them gives a number kk. For each query, Yuta wants to know the number of the pairs (i,j)(1≤i≤n,1≤j≤m)which satisfies if the iith child’s favorite candy is the jjth kind, he will take kk 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 mm 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      
#include <bits/stdc++.h>
using namespace std;
const int maxn=5e4+10;
bitset <maxn> a,b,ans,bx;
int n,m,Q;

void solve(int k)
{
    bx.reset();//bitset bx[a-k]代表這個數%k==0的有幾種,奇數為1,偶數為0
    ans.reset();
    for(int i=k;i>=0;i--)
    {
        ans[i]=((a>>i)&bx).count()&1;//a-k=b*j一共有多少組
        if(b[i])
        {
            for(int j=0;j<=k;j+=i)
                bx.flip(j);
        }
    }
}


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&Q);
        a.reset(),b.reset();
        int x,maxx=-1;
        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);
            maxx=max(maxx,x);
        }
        solve(maxx);
        while(Q--)
        {
            scanf("%d",&x);
            puts(ans[x]?"1":"0");
        }
    }
    return 0;
}