CF1747D.Yet Another Problem
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of n integers a1,a2,a3,…,an .
You have to answer q independent queries, each consisting of two integers l and r .
- Consider the subarray a[l:r] = [al,al+1,…,ar] . You can apply the following operation to the subarray any number of times (possibly zero)-
- Choose two integers L , R such that l≤L≤R≤r and R−L+1 is odd.
- Replace each element in the subarray from L to R with the XOR of the elements in the subarray [L,R] .
- The answer to the query is the minimum number of operations required to make all elements of the subarray a[l:r] equal to 0 or −1 if it is impossible to make all of them equal to 0 .
You can find more details about XOR operation here.
输入格式
The first line contains two integers n and q (1≤n,q≤2⋅105) — the length of the array a and the number of queries.
The next line contains n integers a1,a2,…,an (0≤ai<230) — the elements of the array a .
The i -th of the next q lines contains two integers li and ri (1≤li≤ri≤n) — the description of the i -th query.
输出格式
For each query, output a single integer — the answer to that query.
输入输出样例
输入#1
7 6 3 0 3 3 1 2 3 3 4 4 6 3 7 5 6 1 6 2 2
输出#1
-1 1 1 -1 2 0
说明/提示
In the first query, l=3,r=4 , subarray = [3,3] . We can apply operation only to the subarrays of length 1 , which won't change the array; hence it is impossible to make all elements equal to 0 .
In the second query, l=4,r=6 , subarray = [3,1,2] . We can choose the whole subarray (L=4,R=6) and replace all elements by their XOR (3⊕1⊕2)=0 , making the subarray [0,0,0] .
In the fifth query, l=1,r=6 , subarray = [3,0,3,3,1,2] . We can make the operations as follows:
- Choose L=4,R=6 , making the subarray [3,0,3,0,0,0] .
- Choose L=1,R=5 , making the subarray [0,0,0,0,0,0] .