CF1665E.MinimizOR
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
For each test case print q numbers, where the j -th number is the cost of array 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 .