#P8034. [COCI 2015/2016 #7] Ozljeda

[COCI 2015/2016 #7] Ozljeda

Problem Description

You are given a sequence {a}\{a\} with KK elements. Now define an infinite sequence {x}\{x\} as follows:

$$x_n=\begin{cases} a_n, & 1 \le n \le K, \cr \bigoplus_{i=n-1}^{n-K} x_i, & n > K \end{cases}$$

You are given QQ queries (li,ri)(l_i, r_i). For each query, find the value of i=lrxi\bigoplus_{i=l}^r x_i.

Input Format

The first line contains an integer KK.

The second line contains KK integers aia_i.

The third line contains an integer QQ.

The next QQ lines each contain two integers li,ril_i, r_i.

Output Format

Output QQ lines. Each line contains the answer to the corresponding query.

4
1 3 5 7
3
2 2
2 5
1 5
3
1
0
5
3 3 4 3 2
4
1 2
1 3
5 6
7 9
0
4
7
4

Hint

Constraints

  • For 100%100\% of the testdata, 1K1051 \le K \le 10^5, 0ai<10180 \le a_i \lt 10^{18}, 1Q1061 \le Q \le 10^6, 1liri10181 \le l_i \le r_i \le 10^{18}.

Hints and Notes

This problem is translated from COCI 2015-2016 #7 Task 3 Ozljeda.

The score for this problem follows the original COCI settings, with a full score of 100100.

Translated by ChatGPT 5