F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Fast wyh2000 Transform

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 176    Accepted Submission(s): 37


Problem Description
Young theoretical computer scientist wyh2000 recently falls in love with some strange convolution and optimization algorithms related to them.

Given two arrays of $n$ non-negative integers $a, b$, where the indices are between $0$ and $n-1$. We define their wyh2000-convolution is an array $c$ of length $2n-1$, indices between $0$ and $2n-2$, satisfing
$$c_i\equiv \sum_{j+k=i} \binom{i}{j} a_jb_k (mod \ 3)$$

where $\binom{i}{j}=\frac{i!}{j!(i-j)!}$.Wyh2000 is looking for some algorithm called Fast Wyh2000 Transform (FWT) to solve this problem. Can you help him find it?
 

Input
The input consists of multiple datasets. The first line consists a positive integer $T$, representing the number of datasets.

The next $3T$ lines follow, each $3$ lines form a dataset. On the first line of a dataset lies a positive integer $n$. The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$, which is in the range of $[0,2]$. The third line contains $n$ integers $b_0, b_1, ..., b_{n-1}$, which is also in the range of $[0,2]$.

For pretest, $T=25, n\le 50 000$. For $92\%$ of the test cases, $n\le 100$.

For final test, $T=100, n\le 50000$. For $95\%$ of the test cases, $n\le 200$. For $97\%$ of the test cases, $n\le 10^4$.
 

Output
For each dataset, output a line containing $2n-1$ integers in the range of $[0,2]$, representing $c_0, c_1, ..., c_{2n-2}$.

**please add a space after every line of your output**
 

Sample Input
2 4 0 1 2 1 1 0 1 2 4 1 1 1 1 2 2 2 2
 

Sample Output
0 1 2 1 2 2 1 2 1 2 1 1 1 1
 

Hint

Don't add extra spaces after any line of your hack data.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 04:48:11, Gzip enabled