3527: Nim Game--2018HBCPC B

内存限制:128 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:3 解决:2

题目描述

Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap [From Wikipedia, the free encyclopedia]. The goal of the game is to avoid being the player who doesn't have any object to remove. The player who remove the last project is the winner.

Now KK and TT are playing Nim game with the optimal strategy. There are  heaps of stones. The number of stones in i-th heap is ai. They play this game m times, and KK is the player making the first move. During the i-th time they play the game on the heaps whose index in interval [li,ri]. KK wants to know whether he has a winning strategy or not.

输入

The input consists of several test cases. The first line of the input gives the number of test cases, T(1<=T<=10^3).

For test case, the first line contains two integers n(1<=n<=10^6) and m(1<=m<=10^6), representing the number of heap of stones and the game times.

The second line contains n positive integers a1,a2,a3,···,an(1<=ai<=10^9), representing The number of stones in i-th heap.

In the next m lines, each line contains two integers li,ri, which means the ith game is played on the interval [li,ri].

It's guaranteed that ∑n<=2×10^6 and  ∑m<=2×10^6

输出

For each test case, let fi represents the answer of the th game. If KK has a winning strategy in the th game then fi=1, otherwise fi=0.

Please output  ∑fi*2m-imod10^9+7in which 1<=i<=m

样例输入 复制

3
2 1
1 1
1 2
2 1
1 2
1 2
3 2
1 2 2
1 2
2 3

样例输出 复制

0
1
2

来源/分类