Pro.ID22137 TitleCompressed Suffix Array Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22137 AC3 Submit26 Ratio11.54% 时间&空间限制描述A new technology about suffix array called compressed suffix array is being researched. Let SA be the suffix array for string T. In the base case, we denote SA by SA0, and let n0 = n be the number of its entries. For simplicity in exposition, we assume that n is a power of 2. In the inductive phase k, we start with suffix array SAk, which is available by induction. It has nk = n/(2k) entries and stores a permutation of {1, 2, ..., nk }. (Intuitively, this permutation is that resulting from sorting the suffixes of T whose suffix pointers are multiple of 2k.) We run two main steps to transform SAk into an equivalent but more succinct representation: Step 1. We define a function Ψk where Ψk(i) = j if and only if SAk[i] is odd and SAk[j] = SAk[i] + 1. In summary, for 1 ≤ i ≤ nk , we have Step 2. Pack together the even values from SAk and divide each of them by 2. The resulting values form a permutation of { 1, 2, ... , nk+1}, where nk+1 = nk/ 2 = n / 2k+1 . Store them into a new suffix array SAk+1 of nk+1 entries, and remove the old suffix array SAk. The following example illustrates the effect of a single application of Steps 1-2. SA0 : 15 16 31 13 17 19 28 10 7 4 1 21 24 32 14 30 12 18 27 9 6 3 20 23 29 11 26 8 5 2 22 25 Ψ0: 2 2 14 15 18 23 7 8 28 10 30 31 13 14 15 16 17 18 7 8 21 10 23 13 16 17 27 28 21 30 31 27 SA1 : 8 14 5 2 12 16 7 15 6 9 3 10 13 4 1 11 Ψk can be stored in a particular way in O(n) bits, and SAk+1 occupy half space of SAk, So we can compress the suffix array by repeat steps 1-2. Now, the question is, if we have known SAk+1 and how can we get the SAk ? 输入You will be given a number of cases in the input. Each case starts with a line containing n. The first line contains a positive integer n, which is a power of 2, ( 2 ≤ n ≤ 214 ) Followed by 2 lines. The first line contains n integers represent for Ψk. The second line contains k integers ( k = n / 2 ) represent for SAk+1. The input terminates with EOF. 输出Description A new technology about suffix array called compressed suffix array is being researched. Let SA be the suffix array for string T. In the base case, we denote SA by SA0, and let n0 = n be the number of its entries. For simplicity in exposition, we assume that n is a power of 2. In the inductive phase k, we start with suffix array SAk, which is available by induction. It has nk = n/(2k) entries and stores a permutation of {1, 2, ..., nk }. (Intuitively, this permutation is that resulting from sorting the suffixes of T whose suffix pointers are multiple of 2k.) We run two main steps to transform SAk into an equivalent but more succinct representation: Step 1. We define a function Ψk where Ψk(i) = j if and only if SAk[i] is odd and SAk[j] = SAk[i] + 1. In summary, for 1 ≤ i ≤ nk , we have Step 2. Pack together the even values from SAk and divide each of them by 2. The resulting values form a permutation of { 1, 2, ... , nk+1}, where nk+1 = nk/ 2 = n / 2k+1 . Store them into a new suffix array SAk+1 of nk+1 entries, and remove the old suffix array SAk. The following example illustrates the effect of a single application of Steps 1-2. SA0 : 15 16 31 13 17 19 28 10 7 4 1 21 24 32 14 30 12 18 27 9 6 3 20 23 29 11 26 8 5 2 22 25 Ψ0: 2 2 14 15 18 23 7 8 28 10 30 31 13 14 15 16 17 18 7 8 21 10 23 13 16 17 27 28 21 30 31 27 SA1 : 8 14 5 2 12 16 7 15 6 9 3 10 13 4 1 11 Ψk can be stored in a particular way in O(n) bits, and SAk+1 occupy half space of SAk, So we can compress the suffix array by repeat steps 1-2. Now, the question is, if we have known SAk+1 and how can we get the SAk ? Input You will be given a number of cases in the input. Each case starts with a line containing n. The first line contains a positive integer n, which is a power of 2, ( 2 ≤ n ≤ 214 ) Followed by 2 lines. The first line contains n integers represent for Ψk. The second line contains k integers ( k = n / 2 ) represent for SAk+1. The input terminates with EOF. Output For each input data set output one line, contains the numbers of SAk (each number are separated by a space). Sample Input 32 Sample Output 15 16 31 13 17 19 28 10 7 4 1 21 24 32 14 30 12 18 27 9 6 3 20 23 29 11 26 8 5 2 22 25 Source 样例输入32 样例输出15 16 31 13 17 19 28 10 7 4 1 21 24 32 14 30 12 18 27 9 6 3 20 23 29 11 26 8 5 2 22 25 作者 |