Wavelet Compression
Time limit1sMemory limit128 MB
Given a signal transformed by recursive sum/difference wavelet steps, reconstruct the original samples for each test case.
- Level
Easy3 of 10
- Topics
- Divide and conquer, Simulation, Implementation
- Solved
- No attempts yet
Problem
The discrete wavelet transform is a popular tool for signal compression. Your task is to decompress a one-dimensional signal (a list of integers) that was compressed by the simple wavelet transform described below.
To see how this simple wavelet transform works, suppose we have a list containing an even number of integers. We compute the sum and the difference of each pair of consecutive samples, producing a list of sums and a list of differences, each half the original length. Formally, if the original samples are
a(1), ..., a(n)
then for the -th sum and difference are
The transformed signal is formed by listing all the sums first, followed by all the differences. For instance, if the input signal is
5, 2, 3, 2, 5, 7, 9, 6
then the sums and differences are
s(i) = 7, 5, 12, 15
d(i) = 3, 1, -2, 3
so the transformed signal is
7, 5, 12, 15, 3, 1, -2, 3
The same process is then applied recursively to the first half of the transformed signal (the sums), treating those sums as a new input signal, and it continues until the signal being transformed has length 1. For the example above, the final transformed signal is
39, -15, 2, -3, 3, 1, -2, 3
The length of the original signal is a power of 2, and every original sample is an integer between 0 and 255 inclusive. Given a transformed signal, recover the original samples.
Input
The input consists of several test cases. Each test case is given on its own line: it begins with an integer (, a power of 2) giving the number of samples, followed by the transformed samples. The input ends with a line containing , which is not processed.
Output
For each test case, print the original samples on a single line, separated by single spaces.