Xor sequence

3.4

5 votes
Advanced Data Structures, Data Structures, Medium, Tries
Problem

Given a sequence a1an. You need to perform m queries on it.

In each query, two parameters x,y are given, and we let

l=min(((x+anst)modn)+1,((y+anst)modn)+1)r=max(((x+anst)modn)+1,((y+anst)modn)+1)

In this statement, t is a given constant, which can be 0 or 1. And ans is the answer of last query, with initial value is 0.

You need to find a pair (i,j), satisfies lijr, and maximize ai xor ai+1 xorxor aj.

The answer of this query is ai xor ai+1 xorxor aj.

Input

The first line contains three integers, n, m, and t.

The second line contains n integers, representing the sequence a.

The next m lines, each line contains two integers, x and y.

Output

For each query, output an integer represents the answer.

Constraints

1n,m20000

0t1

0x,y,ai109

Sample Input
5 3 0
8 6 2 4 5
0 4
0 2
2 4
Sample Output
14
14
6
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The actual queries are (1,5),(1,3),(3,5).

You can choose (i,j) as (1,2),(1,2),(3,4) to maximize the value.

Contributers:
Editor Image

?