Suffix Array for Thue-Morse
Time limit2sMemory limit512 MB
Given the order k of a Thue-Morse string of length 2^k, answer q queries for suf[p], the suffix array entries, with k up to 60.
- Level
Hard9 of 10
- Topics
- Array, String, Divide and conquer, Recursion
- Solved
- No attempts yet
Problem
A Thue-Morse string of order is a string of length in which the -th symbol is A if the number of -bits in the binary representation of is even, and B if it is odd.
A suffix array for a string of length is a permutation of the integers from to such that is the list of all non-empty suffixes of in lexicographical order.
Let be the suffix array for the Thue-Morse string of order . Compute the values .
Input
The first line contains two integers and , the order of the Thue-Morse string and the number of queries (, ).
The second line contains integers , separated by spaces. These are the indices to query ().
Output
Print the answers separated by spaces.
Hint
The Thue-Morse string of order is ABBABAAB.