CF1665E.MinimizOR

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn non-negative integers, numbered from 11 to nn.

Let's define the cost of the array aa as min⁡i≠jai∣aj\displaystyle \min_{i \neq j} a_i | a_j, where ∣| denotes the bitwise OR operation.

There are qq queries. For each query you are given two integers ll and rr (l<rl \lt r). For each query you should find the cost of the subarray al,al+1,…,ara_{l}, a_{l + 1}, \ldots, a_{r}.

给你一个长度为 nn 的非负整数数组 aa,元素编号从 11 到 nn。

我们定义数组 aa 的代价为 min⁡i≠jai∣aj\displaystyle \min_{i \neq j} a_i | a_j,其中 ∣| 表示按位或运算。

共有 qq 个查询。对于每个查询,你将得到两个整数 ll 和 rr(满足 l<rl \lt r)。对每个查询,你需要求出子数组 al,al+1,…,ara_{l}, a_{l + 1}, \ldots, a_{r} 的代价。

输入格式

Each test case consists of several test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤1052 \le n \le 10^5) — the length array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2300 \le a_i \lt 2^{30}) — the elements of aa.

The third line of each test case contains an integer qq (1≤q≤1051 \le q \le 10^5) — the number of queries.

Each of the next qq lines contains two integers ljl_j, rjr_j (1≤lj<rj≤n1 \le l_j \lt r_j \le n) — the description of the jj-th query.

It is guaranteed that the sum of nn and the sum of qq over all test cases do not exceed 10510^5.

每个测试用例包含若干个测试案例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试案例的数量。

每个测试案例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)—— 数组 aa 的长度。

每个测试案例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2300 \le a_i \lt 2^{30})—— 数组 aa 的元素。

每个测试案例的第三行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 查询的数量。

接下来的 qq 行中,每行包含两个整数 ljl_j、rjr_j(1≤lj<rj≤n1 \le l_j \lt r_j \le n)—— 第 jj 个查询的描述。

保证所有测试案例中 nn 的总和与 qq 的总和均不超过 10510^5。

输出格式

For each test case print qq numbers, where the jj-th number is the cost of array alj,alj+1,…,arja_{l_j}, a_{l_j + 1}, \ldots, a_{r_j}.

对每个测试用例,输出 qq 个数字,其中第 jj 个数字是数组 alj,alj+1,…,arja_{l_j}, a_{l_j + 1}, \ldots, a_{r_j} 的代价。

输入输出样例

  • 输入#1

    2
    5
    6 1 3 2 1
    4
    1 2
    2 3
    2 4
    2 5
    4
    0 2 1 1073741823
    4
    1 2
    2 3
    1 3
    3 4

    输出#1

    7
    3
    3
    1
    2
    3
    1
    1073741823

说明/提示

In the first test case the array aa is

1102,0012,0112,0102,0012110_2, 001_2, 011_2, 010_2, 001_2.

That's why the answers for the queries are:

  • [1;2][1; 2]: a1∣a2=1102∣0012=1112=7a_1 | a_2 = 110_2 | 001_2 = 111_2 = 7;
  • [2;3][2; 3]: a2∣a3=0012∣0112=0112=3a_2 | a_3 = 001_2 | 011_2 = 011_2 = 3;
  • [2;4][2; 4]: a2∣a3=a3∣a4=a2∣a4=0112=3a_2 | a_3 = a_3 | a_4 = a_2 | a_4 = 011_2 = 3;
  • [2;5][2; 5]: a2∣a5=0012=1a_2 | a_5 = 001_2 = 1.

In the second test case the array aa is

002,102,012,11…12⏟3000_2, 10_2, 01_2, \underbrace{11\ldots 1_2}_{30} (a4=230−1a_4 = 2^{30} - 1).

That's why the answers for the queries are:

  • [1;2][1; 2]: a1∣a2=102=2a_1 | a_2 = 10_2 = 2;
  • [2;3][2; 3]: a2∣a3=112=3a_2 | a_3 = 11_2 = 3;
  • [1;3][1; 3]: a1∣a3=012=1a_1 | a_3 = 01_2 = 1;
  • [3;4][3; 4]: a3∣a4=012∣11…12⏟30=230−1=1073741823a_3 | a_4 = 01_2 | \underbrace{11\ldots 1_2}_{30} = 2^{30} - 1 = 1073741823.

第一个测试用例中,数组 aa 为

1102,0012,0112,0102,0012110_2, 001_2, 011_2, 010_2, 001_2。

因此各查询的答案为:

  • [1;2][1; 2]:a1∣a2=1102∣0012=1112=7a_1 | a_2 = 110_2 | 001_2 = 111_2 = 7;
  • [2;3][2; 3]:a2∣a3=0012∣0112=0112=3a_2 | a_3 = 001_2 | 011_2 = 011_2 = 3;
  • [2;4][2; 4]:a2∣a3=a3∣a4=a2∣a4=0112=3a_2 | a_3 = a_3 | a_4 = a_2 | a_4 = 011_2 = 3;
  • [2;5][2; 5]:a2∣a5=0012=1a_2 | a_5 = 001_2 = 1。

第二个测试用例中,数组 aa 为

002,102,012,11…12⏟3000_2, 10_2, 01_2, \underbrace{11\ldots 1_2}_{30}(即 a4=230−1a_4 = 2^{30} - 1)。

因此各查询的答案为:

  • [1;2][1; 2]:a1∣a2=102=2a_1 | a_2 = 10_2 = 2;
  • [2;3][2; 3]:a2∣a3=112=3a_2 | a_3 = 11_2 = 3;
  • [1;3][1; 3]:a1∣a3=012=1a_1 | a_3 = 01_2 = 1;
  • [3;4][3; 4]:a3∣a4=012∣11…12⏟30=230−1=1073741823a_3 | a_4 = 01_2 | \underbrace{11\ldots 1_2}_{30} = 2^{30} - 1 = 1073741823。

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

首页