CF620F.Xors on Segments

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array with nn integers aia_{i} and mm queries. Each query is described by two integers (lj,rj)(l_{j},r_{j}) .

Let's define the function . The function is defined for only u<=vu<=v .

For each query print the maximal value of the function f(ax,ay)f(a_{x},a_{y}) over all lj<=x,y<=rj, ax<=ayl_{j}<=x,y<=r_{j},\ a_{x}<=a_{y} .

输入格式

The first line contains two integers n,mn,m ( 1<=n<=5104, 1<=m<=51031<=n<=5·10^{4},\ 1<=m<=5·10^{3} ) — the size of the array and the number of the queries.

The second line contains nn integers aia_{i} ( 1<=ai<=1061<=a_{i}<=10^{6} ) — the elements of the array aa .

Each of the next mm lines contains two integers lj,rjl_{j},r_{j} ( 1<=lj<=rj<=n1<=l_{j}<=r_{j}<=n ) – the parameters of the jj -th query.

输出格式

For each query print the value aja_{j} on a separate line — the maximal value of the function f(ax,ay)f(a_{x},a_{y}) over all lj<=x,y<=rj, ax<=ayl_{j}<=x,y<=r_{j},\ a_{x}<=a_{y} .

输入输出样例

  • 输入#1

    6 3
    1 2 3 4 5 6
    1 6
    2 5
    3 4
    

    输出#1

    7
    7
    7
    
  • 输入#2

    1 1
    1
    1 1
    

    输出#2

    1
    
  • 输入#3

    6 20
    10 21312 2314 214 1 322
    1 1
    1 2
    1 3
    1 4
    1 5
    1 6
    2 2
    2 3
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6
    4 4
    4 5
    4 6
    5 5
    5 6
    6 6
    

    输出#3

    10
    21313
    21313
    21313
    21313
    21313
    21312
    21313
    21313
    21313
    21313
    2314
    2315
    2315
    214
    215
    323
    1
    323
    322
    
首页