N-Bonacci Numbers


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

A sequence is called NN-Bonnaci if it is calculated from its previous NN elements. An XOR NN-Bonacci sequence can be formulated in the following format:

F(K)=F(K1)F(K2)F(KN+1)F(KN)F(K) = F(K - 1) \oplus F(K - 2) \oplus \dots \oplus F(K - N + 1) \oplus F(K - N)

Here \oplus denotes bitwise XOR operation. Newbies jury have recently found an interesting sequence which is obtained from the XOR operation on the first KK elements of the XOR NN-Bonacci sequence:

S(K)=F(1)F(2)F(K1)F(K)S(K) = F(1) \oplus F(2) \oplus \dots \oplus F(K - 1) \oplus F(K)

It can be proven that for calculating all of the NN-Bonacci Numbers, only the first NN elements are need to be known. Given the first NN numbers of the XOR NN-Bonacci sequence, your task is to calculate S(K)S(K) for QQ queries.

ورودی🔗

The first line of the input contains two space separated integers NN QQ. The second line contains NN space separated integers denoting F(1),F(2),,F(N)F(1), F(2), \dots , F(N) respectively. Each of the next QQ lines, describes a query by giving an integer KK.

1N,Q1051 \leq N, Q \leq 10^5

خروجی🔗

For each query, you should print the S(K)S(K) in a line.

مثال‌ها🔗

ورودی نمونه ۱🔗

3 4
0 1 2
7
2
5
1000000000
Plain text

خروجی نمونه ۱🔗

3
1
0
0
Plain text