Given a sequence of nn numbers a_1, a_2, \cdots, a_na1​,a2​,⋯,an​ and three functions.

Define a function f(l,r)f(l,r) which returns \oplus a[x]⊕a[x] (l \le x \le rl≤x≤r). The \oplus⊕ represents exclusive OR.

Define a function g(l,r)g(l,r) which returns \oplus f(x,y)(l \le x \le y \le r)⊕f(x,y)(l≤x≤y≤r).

Define a function w(l,r)w(l,r) which returns \oplus g(x,y)(l \le x \le y \le r)⊕g(x,y)(l≤x≤y≤r).

You are also given a number of xor-queries. A xor-query is a pair (i, ji,j) (1 \le i \le j \le n1≤i≤j≤n). For each xor-query (i, j)(i,j), you have to answer the result of function w(l,r)w(l,r).

Input

Line 11: t (1 \le t \le 20)t(1≤t≤20).

For each test case:

Line 11: n (1 \le n \le 100000)n(1≤n≤100000).

Line 22: nn numbers a_1, a_2, \cdots, a_n (1 \le a_i \le 10^9)a1​,a2​,⋯,an​(1≤ai​≤109).

Line 33: q (1 \le q \le 100000)q(1≤q≤100000), the number of xor-queries.

In the next qq lines, each line contains 22 numbers i, ji,j representing a xor-query (1 \le i \le j \le n)(1≤i≤j≤n).

It is guaranteed that sum of nn and q \le 10^6q≤106.

Output

For each xor-query (i, j)(i,j), print the result of function w(i,j)w(i,j) in a single line.

样例输入复制

1
5
1 2 3 4 5
5
1 3
1 5
1 4
4 5
3 5

样例输出复制

2
4
0
1
4

解题报告:

记录每个数字出现的次数,奇数次说明这个数存在于答案中,偶数次相当于对答案没有贡献。打表找规律发现跟4的倍数有关,所以我们预处理以4为分组的异或和,然后O(1)输出结果就可以了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll a[MAX];
ll x0[MAX],x1[MAX],x2[MAX],x3[MAX];
ll all[MAX];
int main()
{int t;cin>>t;int n,q;while(t--) {scanf("%d",&n);for(int i = 1; i<=n; i++) {scanf("%lld",a+i);x0[i] = x0[i-1];x1[i] = x1[i-1];x2[i] = x2[i-1];x3[i] = x3[i-1];all[i] = all[i-1]^a[i];if(i%4==0) x0[i] ^= a[i];else if(i%4==1) x1[i] ^= a[i];else if(i%4==2) x2[i] ^= a[i];else if(i%4==3) x3[i] ^= a[i];}scanf("%d",&q);int l,r,len;ll ans;while(q--) {scanf("%d%d",&l,&r);len = r-l+1;if(len%2==0) {if(len%4==0) ans=0;else {if(l%4==0) {ans = x1[r]^x1[l];ans ^= x0[r]^x0[l-1];}else if(l%4==1) {ans = x2[r]^x2[l];ans ^= x1[r]^x1[l-1];}else if(l%4==2) {ans = x3[r]^x3[l];ans ^= x2[r]^x2[l-1];}else if(l%4==3) {ans = x0[r]^x0[l];ans ^= x3[r]^x3[l-1];}}}else {if(len%4 == 1) {               if(l%4==0) {ans = x0[r]^x0[l-1];                 }else if(l%4==1) {ans = x1[r]^x1[l-1];                       }else if(l%4==2) {ans = x2[r]^x2[l-1];}else if(l%4==3) {ans = x3[r]^x3[l-1];                  }                                       }else {if(l%4==0) {ans = x1[r]^x1[l-1];                  }else if(l%4==1) {ans = x2[r]^x2[l-1];                       }else if(l%4==2) {ans = x3[r]^x3[l-1];                       }else if(l%4==3) {ans = x0[r]^x0[l-1];                       }                                       }}printf("%lld\n",ans);}}return 0 ;
}

【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表)相关推荐

  1. 【计蒜客 - 2019南昌邀请赛网络赛 - I】Max answer(单调栈,RMQ)

    题干: Alice has a magic array. She suggests that the value of a interval is equal to the sum of the va ...

  2. 【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)

    题干: David has a white board with 2 \times N2×N grids.He decides to paint some grids black with his b ...

  3. 【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)

    题干: Give a string SS and NN string T_iTi​ , determine whether T_iTi​ is a subsequence of SS. If ti i ...

  4. 计蒜客 2019 蓝桥杯省赛 B 组模拟赛(一)

    D题:马的管辖 二进制枚举方案.判断该方案是否全部能被覆盖,将最优方案存下来并进行剪枝. #include<iostream> #include<cstring> #inclu ...

  5. 计蒜客 2019 蓝桥杯省赛 A 组模拟赛(一) B:炮台实验

    题目描述 蒜头君在玩一个战争模拟游戏,他有高度为 1,2,3,-,n 的炮台各一个,他需要把这 n 个炮台从左往右排成一行,并且炮口都朝向右边. 在这个游戏中,所有炮台发射的炮弹会摧毁前方所有高度比自 ...

  6. 计蒜客2019蓝桥杯省赛B组模拟赛(一)题目及解析

    蓝桥杯历年真题题目及题解目录汇总   A. 结果填空:钟表 题库链接 分值: 5 一天蒜头君 22:28:45 开始睡觉,06:24:26 醒来之后,蒜头君在想,今天我睡了多久? 请你告诉蒜头君睡了& ...

  7. 计蒜客2019蓝桥杯省赛 B 组模拟赛(一)轻重搭配|

    题解:这题一看就知道是贪心问题,但问题是怎么贪,直接暴力循环一遍,TLE.选错贪心思路,只能过一小部分数据,正确贪心思路:从前一半遍历,在后一半中找到比当前元素的两倍大的数 代码如下: #includ ...

  8. 2019南昌邀请赛网络赛

      A. PERFECT NUMBER PROBLEM 这题没什么要说的. #include<bits/stdc++.h>using namespace std;int main(){co ...

  9. 北京林业大学“计蒜客”杯程序设计竞赛 网络赛 马踏棋盘的问题

    //使用bfs #include<stdio.h> #include<iostream> #include<utility> #include<queue&g ...

最新文章

  1. 微软、海思、任天堂等50多家知名公司源代码泄露,人人均可公开访问
  2. docker 网络 实现
  3. 003_commons-logging与slf4j和log4j与logback
  4. try not let others think you are good enough
  5. 常见的CSS和HTML面试题
  6. SQL Server遗失管理权限账号密码怎么办?
  7. 为什么有些女孩在发现渣男的真面目以后,还喜欢他们?
  8. jedis操作set_使用Redis来进行缓存操作
  9. 微型计算机中常体积的,微型计算机原理及应用第2章.ppt
  10. c语言纵行输入大写字母图形,GitHub - xswei/SVG_Essentials: 《SVG精髓》 阅读笔记
  11. Linux cmd 常用快捷键(自用)
  12. 批量检测支付宝是否开通
  13. 榆熙电商:拼多多怎样判断商品是否被降权?原因有哪些?
  14. Windows 2000/xp/2003 常用补丁下载
  15. java快速排序的时间复杂度_程序猿必备排序算法及其时间复杂度分析
  16. A tutorial on Principal Components Analysis - 主成分分析(PCA)教程
  17. 「业务架构」EA874:业务架构层
  18. 计算机net是什么意思翻译,net是什么意思_net翻译_读音_用法_翻译
  19. 精致好看的真无线耳机,音质也不错,JEET ONE升级版上手
  20. 命运冠位指定服务器连接中断,FGO命运冠位指定:从肝帝到如今的服务器蛀虫,这玩家经历什么了...

热门文章

  1. 引用到网站绝对路径Server.MapPath(~/myfile.mdb)
  2. 为什么机器学习算法要与人类水平比较
  3. [Leetcode][第1392题][JAVA][最快乐前缀][KMP][字符串编码]
  4. 自己的路 php,生活感悟的句子:走自己的路,做自己的事
  5. 该文件没有与之关联的程序来执行该操作_Liunx tty子系统分析之三 tty字符设备文件操作接口说明...
  6. 1388C. Uncle Bogdan and Country Happiness
  7. RT-Thread I2C设备驱动框架的对接使用
  8. c语言输入坐标判断位置,〓求助〓谁能帮忙编个程序:输入N个点坐标,判断能否构成多边形....
  9. idea 设置java栈空间,如何为Intellij编译器提供更多堆空间?
  10. Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)