问题1552--Nim Game

1552: Nim Game

时间限制: 1 Sec  内存限制: 128 MB
提交: 585  解决: 96
[状态] [讨论版] [提交] [命题人:]
题目描述
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 |Fṝõṃ Wìǩìqèḋìa«țȟè ḟṝèè èñćẏćḽõqèḋìa¦. 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 n 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 ≤ 103).
For test case, the first line contains two integers n(1 ≤ n ≤ 106 ) and m(1 ≤ m ≤ 106), representing the number of heap of stones and the game times.
The second line contains n positive integers a1, a2, ⋯ , an (1 ≤ ai ≤ 109), representing The number of stones in i‑th heap.
In the next m lines, each line contains two integers li, ri , which means the $i: KaTeX parse error: $ within math mode$th game is played on the interval[li , ri].
It’s guaranteed that ∑ n ≤ 2 × 10and  ∑ m ≤ 2 × 106
输出
For each test case, let fi represents the answer of the i-th game.
If KK has a winning strategy in the i-th game then fi=1, otherwise fi=0. Please output ∑ fi ∗ 2m-i mod 10 + 7,in which 1 ≤ i ≤ m

样例输入 Copy
3
2 1
1 1
1 2
2 1
1 2
1 2
3 2
1 2 2
1 2
2 3
样例输出 Copy
0
1
2
来源/分类