#Lutece1393. An easy DSP problem
An easy DSP problem
Migrated from Lutece 1393 An easy DSP problem
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
Brother HeZai is a good student, he is good at (数字信号处理)! He thinks any problem can be solved by (离散傅里叶变换),but you don’t think so and you give Brother HeZai an “easy” problem.
Problem’s contents are as follows.
(快速傅里叶变换) is an algorithm used to calculate (卷积). Specifically, if , and are sequences with length , which are indexed from to
And we can calculate c fast using Fast Fourier Transformation.
You made a little change on this formula. Now
To make things easier, a is a permutation of integers from to , and is a sequence only containing and . Given and , Brother HeZai needs to calculate .
Brother HeZai is so powerful! He solves it immediately! But now it’s your turn, can you solve it?
Input
The first line only contains an positive integer ( ) , represents there are test cases.
For each test case:
The first line contain one integer , indicating the length of .
The next line contains a permutation from to , indicating the elements of .
The next line contains a 0-1 sequence of length , indicating the elements of .
Output
For each test case, output the element of in line.
Samples
2
3
1 3 2
1 0 0
5
2 1 4 5 3
1 1 1 0 1
1
3
2
2
2
4
5
5
Note
Resources
IEEEXTREME Programming Competition