CF1100F.Ivan and Burgers

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ivan loves burgers and spending money. There are nn burger joints on the street where Ivan lives. Ivan has qq friends, and the ii-th friend suggested to meet at the joint lil_i and walk to the joint rir_i (li≤ri)(l_i \leq r_i). While strolling with the ii-th friend Ivan can visit all joints xx which satisfy li≤x≤ril_i \leq x \leq r_i.

For each joint Ivan knows the cost of the most expensive burger in it, it costs cic_i burles. Ivan wants to visit some subset of joints on his way, in each of them he will buy the most expensive burger and spend the most money. But there is a small issue: his card broke and instead of charging him for purchases, the amount of money on it changes as follows.

If Ivan had dd burles before the purchase and he spent cc burles at the joint, then after the purchase he would have d⊕cd \oplus c burles, where ⊕\oplus denotes the bitwise XOR operation.

Currently Ivan has 22100−12^{2^{100}} - 1 burles and he wants to go out for a walk. Help him to determine the maximal amount of burles he can spend if he goes for a walk with the friend ii. The amount of burles he spends is defined as the difference between the initial amount on his account and the final account.

伊万喜欢汉堡和花钱。在伊万居住的街道上有 nn 家汉堡店。伊万有 qq 位朋友,其中第 ii 位朋友建议在第 lil_i 家店见面,然后一起步行到第 rir_i 家店(满足 li≤ril_i \leq r_i)。在与第 ii 位朋友散步途中,伊万可以访问所有满足 li≤x≤ril_i \leq x \leq r_i 的汉堡店 xx。

对于每家汉堡店,伊万都知道其中最贵汉堡的价格,第 ii 家店的最贵汉堡价格为 cic_i 卢布。伊万希望在前往途中的某些店铺停留,并在每家停留的店铺购买最贵的汉堡,从而尽可能多地花钱。但这里有个小问题:他的银行卡坏了,无法正常扣款;取而代之的是,卡内余额会按如下方式变化:

若伊万在消费前有 dd 卢布,而在某家店花费了 cc 卢布,则消费后他的余额变为 d⊕cd \oplus c 卢布,其中 ⊕\oplus 表示按位异或运算。

目前伊万卡内余额为 22100−12^{2^{100}} - 1 卢布,他准备出门散步。请帮助他计算:若他与第 ii 位朋友一同散步,他最多能“花费”多少卢布?此处“花费”的金额定义为账户初始余额与最终余额之差。

输入格式

The first line contains one integer nn (1≤n≤500 0001 \leq n \leq 500\,000) — the number of burger shops.

The next line contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (0≤ci≤1060 \leq c_i \leq 10^6), where cic_i — the cost of the most expensive burger in the burger joint ii.

The third line contains one integer qq (1≤q≤500 0001 \leq q \leq 500\,000) — the number of Ivan's friends.

Each of the next qq lines contain two integers lil_i and rir_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n) — pairs of numbers of burger shops between which Ivan will walk.

第一行包含一个整数 nn(1≤n≤500 0001 \leq n \leq 500\,000)——汉堡店的数量。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(0≤ci≤1060 \leq c_i \leq 10^6),其中 cic_i 表示第 ii 家汉堡店中最贵汉堡的价格。

第三行包含一个整数 qq(1≤q≤500 0001 \leq q \leq 500\,000)——伊万的朋友数量。

接下来的 qq 行中,每行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n)——表示伊万将行走的汉堡店编号区间。

输出格式

Output qq lines, ii-th of which containing the maximum amount of money Ivan can spend with the friend ii.

输出 qq 行,其中第 ii 行包含 Ivan 与第 ii 位朋友一起所能花费的最大金额。

输入输出样例

  • 输入#1

    4
    7 2 3 4
    3
    1 4
    2 3
    1 3

    输出#1

    7
    3
    7
  • 输入#2

    5
    12 14 23 13 7
    15
    1 1
    1 2
    1 3
    1 4
    1 5
    2 2
    2 3
    2 4
    2 5
    3 3
    3 4
    3 5
    4 4
    4 5
    5 5

    输出#2

    12
    14
    27
    27
    31
    14
    25
    26
    30
    23
    26
    29
    13
    13
    7

说明/提示

In the first test, in order to spend the maximum amount of money with the first and third friends, Ivan just needs to go into the first burger. With a second friend, Ivan just go to the third burger.

In the second test for a third friend (who is going to walk from the first to the third burger), there are only 8 options to spend money — 00, 1212, 1414, 2323, 12⊕14=212 \oplus 14 = 2, 14⊕23=2514 \oplus 23 = 25, 12⊕23=2712 \oplus 23 = 27, 12⊕14⊕23=2012 \oplus 14 \oplus 23 = 20. The maximum amount of money it turns out to spend, if you go to the first and third burger — 12⊕23=2712 \oplus 23 = 27.

在第一个测试用例中,为了与第一位和第三位朋友花费最多的钱,伊万只需进入第一家汉堡店即可。对于第二位朋友,伊万只需前往第三家汉堡店。

在第二个测试用例中,对于第三位朋友(他将从第一家汉堡店走到第三家汉堡店),共有 8 种花钱的方式——00、1212、1414、2323、12⊕14=212 \oplus 14 = 2、14⊕23=2514 \oplus 23 = 25、12⊕23=2712 \oplus 23 = 27、12⊕14⊕23=2012 \oplus 14 \oplus 23 = 20。若前往第一家和第三家汉堡店,则可花费的最大金额为 12⊕23=2712 \oplus 23 = 27。

输入解题思路,AI测评打分。不知道怎么写?

首页