CF1665E.MinimizOR
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of n non-negative integers, numbered from 1 to n.
Let's define the cost of the array a as i=jminai∣aj, where ∣ denotes the bitwise OR operation.
There are q queries. For each query you are given two integers l and r (l<r). For each query you should find the cost of the subarray al,al+1,…,ar.
给你一个长度为 n 的非负整数数组 a,元素编号从 1 到 n。
我们定义数组 a 的代价为 i=jminai∣aj,其中 ∣ 表示按位或运算。
共有 q 个查询。对于每个查询,你将得到两个整数 l 和 r(满足 l<r)。对每个查询,你需要求出子数组 al,al+1,…,ar 的代价。
输入格式
Each test case consists of several test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains an integer n (2≤n≤105) — the length array a.
The second line of each test case contains n integers a1,a2,…,an (0≤ai<230) — the elements of a.
The third line of each test case contains an integer q (1≤q≤105) — the number of queries.
Each of the next q lines contains two integers lj, rj (1≤lj<rj≤n) — the description of the j-th query.
It is guaranteed that the sum of n and the sum of q over all test cases do not exceed 105.
每个测试用例包含若干个测试案例。第一行包含一个整数 t(1≤t≤104)—— 测试案例的数量。
每个测试案例的第一行包含一个整数 n(2≤n≤105)—— 数组 a 的长度。
每个测试案例的第二行包含 n 个整数 a1,a2,…,an(0≤ai<230)—— 数组 a 的元素。
每个测试案例的第三行包含一个整数 q(1≤q≤105)—— 查询的数量。
接下来的 q 行中,每行包含两个整数 lj、rj(1≤lj<rj≤n)—— 第 j 个查询的描述。
保证所有测试案例中 n 的总和与 q 的总和均不超过 105。
输出格式
For each test case print q numbers, where the j-th number is the cost of array alj,alj+1,…,arj.
对每个测试用例,输出 q 个数字,其中第 j 个数字是数组 alj,alj+1,…,arj 的代价。
输入输出样例
输入#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 a is
1102,0012,0112,0102,0012.
That's why the answers for the queries are:
- [1;2]: a1∣a2=1102∣0012=1112=7;
- [2;3]: a2∣a3=0012∣0112=0112=3;
- [2;4]: a2∣a3=a3∣a4=a2∣a4=0112=3;
- [2;5]: a2∣a5=0012=1.
In the second test case the array a is
002,102,012,3011…12 (a4=230−1).
That's why the answers for the queries are:
- [1;2]: a1∣a2=102=2;
- [2;3]: a2∣a3=112=3;
- [1;3]: a1∣a3=012=1;
- [3;4]: a3∣a4=012∣3011…12=230−1=1073741823.
第一个测试用例中,数组 a 为
1102,0012,0112,0102,0012。
因此各查询的答案为:
- [1;2]:a1∣a2=1102∣0012=1112=7;
- [2;3]:a2∣a3=0012∣0112=0112=3;
- [2;4]:a2∣a3=a3∣a4=a2∣a4=0112=3;
- [2;5]:a2∣a5=0012=1。
第二个测试用例中,数组 a 为
002,102,012,3011…12(即 a4=230−1)。
因此各查询的答案为:
- [1;2]:a1∣a2=102=2;
- [2;3]:a2∣a3=112=3;
- [1;3]:a1∣a3=012=1;
- [3;4]:a3∣a4=012∣3011…12=230−1=1073741823。
输入解题思路,AI测评打分。不知道怎么写?