区间异或和(预处理前后缀异或)

Problem Description

给出一个长度为nn的序列A_1,A_2,\cdots,A_NA1​,A2​,⋯,AN

有qq次询问,每次询问给出l, rl,r,请你回答A_l\oplus A_{l+1}\oplus A_{l+2} ...\oplus A_{r}Al​⊕Al+1​⊕Al+2​...⊕Ar​是多少。

Input

 
 

第一行输入一个整数nn,满足1\leq n\leq 1000001≤n≤100000。

第二行输入nn个整数,A_1,A_2,...,A_n A1​,A2​,...,An​。1\leq A_i\leq 10000000001≤Ai​≤1000000000。

第三行输入一个整数qq。1\leq q\leq 1000001≤q≤100000。

第44至第q + 4q+4行,每行输入两个整数l,rl,r,1\leq l\leq r\leq n1≤lrn。

Output

 
 

输出共qq行。

每行输出一个整数,表示A_l\oplus A_{l+1}\oplus A_{l+2} ...\oplus A_{r}Al​⊕Al+1​⊕Al+2​...⊕Ar​。

Sample Input

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

Sample Output

3
3
0
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <cctype>
#include <cstdlib>
#include <deque>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 3e6 + 5;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))



int a[MAXN];
int pre1[MAXN];
int pre2[MAXN];
int n;
int q;
int main() {
	scanf("%d", &n);
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		sum ^= a[i];
		pre1[i] = pre1[i - 1] ^ a[i];
	}
	for (int i = n; i >= 1; i--) {
		pre2[i] = pre2[i + 1] ^ a[i];
	}
	scanf("%d", &q);
	int l, r;
	while (q--) {
		scanf("%d %d", &l, &r);
		printf("%d\n", pre1[l - 1]^sum ^ pre2[r + 1]);
	}
	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值