InverseHaar1D
SRM 275 · 2005-11-30 · by NeverMore
Problem Statement
The above describes a level-1 transform. To perform a level-2 transform, we repeat the above procedure on the first half of the sequence obtained from the level-1 transform. The second half of the sequence remains unchanged from the previous level. This pattern continues for higher level transforms (i.e., a level-3 transform operates with the first quarter of the sequence, and so on). Note that this is always possible when the number of elements is a power of 2.
Given the output of a level-L 1D Haar transform in
See the examples for clarification.
Constraints
- transformedData will contain exactly 2, 4, 8, 16 or 32 elements.
- Each element of transformedData will be between -10000 and 10000, inclusive.
- L will be between 1 and log2(# of elements in transformedData) inclusive.
- The elements of transformedData will constitute a valid Haar transform.
{101, -53}
1
Returns: {24, 77 }
Consider the sequence {24, 77}. Then, the level-1 Haar transform is simply {24+77, 24-77} = {101, -53}, which is exactly transformedData.
{3, 8, -1, -2}
1
Returns: {1, 2, 3, 5 }
Consider the sequence {1, 2, 3, 5}. Start by forming 3=1+2, the sum of the first pair; 8=3+5, the sum of the second pair; -1=1-2, the difference of the first pair; and finally, -2=3-5, the difference of the second pair. To form the output, we create a sequence of the sums in order, and the differences in order. Then, the output for the Haar wavelet transform would be {3, 8, -1, -2}, which is exactly transformedData.
{11, -5, -1, -2}
2
Returns: {1, 2, 3, 5 }
From the previous example, the level-1 Haar transform of {1, 2, 3, 5} gives {3, 8, -1, -2}. Then, the level-2 transform of {1, 2, 3, 5} is simply {11, -5, -1, -2} (11=3+8, -5=3-8), which is once again exactly transformedData.
{369, 477, 451, 262, 47, 135,
-125, -2, 18, -23, 30, 101,
-5, -18, 54, -20, 11, 45, -5,
70, -24, 2, -50, 15, 55, -62,
-23, -17, 44, -8, -44, -52}
3
Returns: {62, 51, 70, 25, 32, 37, 81, 11, 72, 96, 70, 68, 43, 93, 25, 10, 67, 12, 11, 73, 56, 79, 68, 85, 68, 24, 15, 23, 6, 50, 12, 64 }
{20, 0, -4, 4, -1, -1, 1, 1}
3
Returns: {1, 2, 3, 4, 4, 3, 2, 1 }
Submissions are judged against all 55 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class InverseHaar1D with a public method vector<int> transform(vector<int> transformedData, int L) · 55 test cases · 2 s / 256 MB per case