题目链接:https://nanti.jisuanke.com/t/38230
Description
Given a sequence of nn numbers a1,a2,…,anand three functions.
Define a function f(l,r)f(l,r) which returns ⊕a[x] (l≤x≤r). The ⊕ represents exclusive OR.
Define a function g(l,r)g(l,r) which returns ⊕f(x,y)(l≤x≤y≤r).
Define a function w(l,r)w(l,r) which returns ⊕g(x,y)(l≤x≤y≤r).
You are also given a number of xor-queries. A xor-query is a pair (i, j) (1≤i≤j≤n). For each xor-query (i,j), you have to answer the result of function w(l,r).
Input
Line 1: t(1≤t≤20).
For each test case:
Line 1: n(1≤n≤100000).
Line 2: n numbers a1,a2,…,an (1<=ai<=109)
Line 3:q(1≤q≤100000), the number of xor-queries.
In the next q lines, each line contains 2 numbers i,j representing a xor-query (1≤i≤j≤n).
It is guaranteed that sum of n and q <=106
Output
For each xor-query (i,j), print the result of function w(i,j) in a single line.
Sample Input
1
5
1 2 3 4 5
5
1 3
1 5
1 4
4 5
3 5
Sample Output
2
4
0
1
4
思路
观察样例觉得应该是按区间长度找规律,然后就打了表
第i行代表区间长度为i时每一位所做的贡献
然后发现是4的循环节
然后dp一下,dp[i][j]表示以第i位为查询的左端点区间长度为第j种(1<=j<=4),到第n位的答案。
1 |
|