Suffix Array for Thue-Morse

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

A Thue-Morse string of order kk is a string of length 2k2^{k} in which ii-th symbol equals to 'A' if the number of 11-bits in binary representation of i1i - 1 is even, and 'B' if it is odd.

A suffix array for string ss of length nn is a permutation suf\mathit{suf} of integers from 11 to nn such that s\[suf\[1]..n]s\[\mathit{suf}\[1]..n], s\[suf\[2]..n]s\[\mathit{suf}\[2]..n], \ldots, s\[suf\[n]..n]s\[\mathit{suf}\[n]..n] is the list of non-empty suffixes of ss sorted in lexicographical order.

Let suf\mathit{suf} be the suffix array for Thue-Morse string of order kk. You task is to calculate qq values: suf\[p_1]\mathit{suf}\[p\_1], suf\[p_2]\mathit{suf}\[p\_2], \ldots, suf\[p_q]\mathit{suf}\[p\_q].

입력

The first line of input contains two integers kk and qq: the order of Thue-Morse string and the number of queries (0k600 \le k \le 60, 1q1051 \le q \le 10^5).

The second line contains qq integers p_1p\_1, p_2p\_2, \ldots, p_qp\_q separated by spaces: the required indices (1p_i2k1 \le p\_i \le 2^k).

출력

Output qq answers to the queries, separated by spaces.

힌트

Thue-Morse string of order 33 is "ABBABAAB".