1. 程式人生 > >[Codeforces Round #483 (Div. 1) -B] XOR-pyramid

[Codeforces Round #483 (Div. 1) -B] XOR-pyramid

洛谷傳送門

題目描述

For an array b of length m we define the function f as f(b)={b[1]if m=1f(b[1]b[2],b[2]b[3],,b[m1]b[m])otherwise,, where is bitwise exclusive OR.

For example,

f(1,2,4,8)=f(12,24,48)=f(3,6,12)=f(36,612)=f(5,10)=f(510)=f(15)=15

You are given an array a and a few queries. Each query is represented as two integers l and r . The answer is the maximum value of f on all continuous subsegments of the array al,al+1,,ar .

輸入輸出格式

輸入格式:

The first line contains a single integer n ( 1n50001n5000 ) — the length of a .

The second line contains n integers a1,a2,,an ( 0ai2301 ) — the elements of the array.

The third line contains a single integer q ( 1q100000 ) — the number of queries.

Each of the next

q lines contains a query represented as two integers l , r ( 1lrn ).

輸出格式:

Print q 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 [3,6] , for second query — [2,5] , for third — [3,4] , for fourth — [1,2] .

題目大意

給你一個序列, 一次操作可以將長為n一段序列的相鄰元素兩兩異或, 得到n1個值(順序不變), 如此操作n1次可以得到一個值。 現給出q組詢問, 每次詢問在[l,r]範圍內操作其中子序列可以得到最大值是多少。、

解題分析

首先很容易看出[l,r]的序列每個元素異或的次數和