CF1747D.Yet Another Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers a1,a2,a3,,ana_1, a_2, a_3, \ldots, a_n .

You have to answer qq independent queries, each consisting of two integers ll and rr .

  • Consider the subarray a[l:r]a[l:r] == [al,al+1,,ar][a_l, a_{l+1}, \ldots, a_r] . You can apply the following operation to the subarray any number of times (possibly zero)-
    1. Choose two integers LL , RR such that lLRrl \le L \le R \le r and RL+1R - L + 1 is odd.
    2. Replace each element in the subarray from LL to RR with the XOR of the elements in the subarray [L,R][L, R] .
  • The answer to the query is the minimum number of operations required to make all elements of the subarray a[l:r]a[l:r] equal to 00 or 1-1 if it is impossible to make all of them equal to 00 .

You can find more details about XOR operation here.

输入格式

The first line contains two integers nn and qq (1n,q2105)(1 \le n, q \le 2 \cdot 10^5) — the length of the array aa and the number of queries.

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai<230)(0 \le a_i \lt 2^{30}) — the elements of the array aa .

The ii -th of the next qq lines contains two integers lil_i and rir_i (1lirin)(1 \le l_i \le r_i \le n) — the description of the ii -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=4l = 3, r = 4 , subarray = [3,3][3, 3] . We can apply operation only to the subarrays of length 11 , which won't change the array; hence it is impossible to make all elements equal to 00 .

In the second query, l=4,r=6l = 4, r = 6 , subarray = [3,1,2][3, 1, 2] . We can choose the whole subarray (L=4,R=6)(L = 4, R = 6) and replace all elements by their XOR (312)=0(3 \oplus 1 \oplus 2) = 0 , making the subarray [0,0,0][0, 0, 0] .

In the fifth query, l=1,r=6l = 1, r = 6 , subarray = [3,0,3,3,1,2][3, 0, 3, 3, 1, 2] . We can make the operations as follows:

  1. Choose L=4,R=6L = 4, R = 6 , making the subarray [3,0,3,0,0,0][3, 0, 3, 0, 0, 0] .
  2. Choose L=1,R=5L = 1, R = 5 , making the subarray [0,0,0,0,0,0][0, 0, 0, 0, 0, 0] .
首页