#P11055. [2016杭电多校]Magic Number
[2016杭电多校]Magic Number
Magic Number
Problem Description
Illya has magic numbers. The number can be represented by a binary with the length of . Combining these strings gets a long string with the length of . The strings from to is the binary of from low to high. One day, Rin input Illya’s magic numbers into a program to create new magic numbers. The new number is . Here is the code of program in C++: for(int i = 1; i <= n; i++) b[i] = flag[i] = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if( (1 << (j - 1) & a[i]) > 0){ if(!flag[i]) b[i] = b[j], flag[i] = 1; else b[i] &= b[j]; } } b[i] ^= 1 << (i - 1); } After that, Rin leave questions. The question is a number , which can be represented by a binary with the length of . Combining these strings gets a long string with the length of (). The strings from to is the binary of from low to high. For each question, Rin requires Illya to calculate number . for(int i = 1; i <= n; i++){ d[i] = 0; for(int j = 1; j <= len[i]; j++) if(j <= n && (1 << (j - 1) & c[i]) > 0) d[i] |= b[j]; } The answer of question is the number of ones in the binary of .
Input
There are multiple test cases. the first line contains a single integers , denoting the number of test cases. For each case, the first line contains two integers and , denoting the number of magic numbers and the number of ones in a long string . The second line contains integers, the integer denotes = 1. The others are equal to 0. The third line contains two integer and , denoting the number of questions and the number of ones in a long string . The forth line contains integers, the integer denotes the length of binary of the question . The fifth line contains integers, the integer denotes = 1. The others are equal to 0.
Output
For each case, first output "Case #x:". Each question should print one line: the line of these denotes the answer of question. There is no blank line between two cases.
Sample Input
1
3 4
0 1 4 5
3 6
2 3 3
0 1 2 4 6 7
Sample Output
Case #1:
2
3
3
Author
UESTC
Source
2016 Multi-University Training Contest 6