[Codeforces Round #483 (Div. 1) -B] XOR-pyramid
洛谷傳送門
題目描述
For an array of length we define the function as , where is bitwise exclusive OR.
For example,
You are given an array and a few queries. Each query is represented as two integers and . The answer is the maximum value of on all continuous subsegments of the array .
輸入輸出格式
輸入格式:
The first line contains a single integer ( ) — the length of .
The second line contains integers ( ) — the elements of the array.
The third line contains a single integer ( ) — the number of queries.
Each of the next
輸出格式:
Print lines — the answers for the queries.
輸入輸出樣例
輸入樣例#1:
3
8 4 1
2
2 3
1 2
輸出樣例#1:
5
12
輸入樣例#2:
6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2
輸出樣例#2:
60
30
12
3
說明
In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are , for second query — , for third — , for fourth — .
題目大意
給你一個序列, 一次操作可以將長為一段序列的相鄰元素兩兩異或, 得到個值(順序不變), 如此操作次可以得到一個值。 現給出組詢問, 每次詢問在範圍內操作其中子序列可以得到最大值是多少。、
解題分析
首先很容易看出的序列每個元素異或的次數和