#Lutece2757. 暴力题

暴力题

Migrated from Lutece 2757 暴力题

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

这是一道暴力题。

你有一个长度为 nn 的序列 SS , 每次询问一个区间 l,rl,r ,你需要找到区间内所有子段异或和的最大值,即

$$\max_{l \le i \le j \le r}\{S_i\oplus S_{i+1}\oplus\cdots\oplus S_{j-1} \oplus S_j\} $$

为了保证做法的在线性,本题采用了特殊方式的读入。 假设你维护了一个变量 lastanslastans,初始值为 00 。 对于每个读入的区间 [l,r][l, r],设

$$x = ((l + lastans) \bmod n) + 1\\ y = ((r + lastans) \bmod n) + 1 $$

则实际上询问的区间为 [min(x,y),max(x,y)][\min(x,y),\max(x,y)]

Input

第一行输入两个正整数 n,mn,m,分别表示序列长度和询问次数。 第二行输入 nn 个非负整数 S1,S2,,SnS_1, S_2, \cdots, S_n,即序列 SS。 第 33 至第 m+2m+2 行,每行输入 l,rl,r,表示一次询问。

Output

输出 mm 行,每行一个整数,表示对应询问的答案。

Samples

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

Constraints

1n120001\le n \le 120001m60001\le m \le 6000 0l,r,Si<2310\le l,r,S_i < 2^{31}

Resources

2022 UESTC ICPC Training for Data Structures