#Lutece1450. Magic Number
Magic Number
Migrated from Lutece 1450 Magic Number
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
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.
Samples
1
3 4
0 1 4 5
3 6
2 3 3
0 1 2 4 6 7
Case #1:
2
3
3
Resources
2016 Multi-University Training Contest 6