C - Copy (hdu)

Kayzin has a list of integers, initially the list is a_1,a_2,\ldots,a_na1​,a2​,…,an​. He will execute qq operations.

For an operation of first type, he will select an interval [l_i, r_i][li​,ri​], copy and insert it to the end of the interval.

For an operation of second type, he wonder the x_ixi​-th integer of the list.

You need to print the xor sum of all the answers of second type operations.

ps: What is xor? The xor value of two integers is equal to addition in binary without carry.

ps: nn is a constant for each test case.

Input

First line is an integer TT, indicating the number of test cases. For each test case:

First line is 2 integers n,qn,q, indicating the length of initial list and the number of operations.

Next line is nn integers a_1,a_2,\ldots,a_na1​,a2​,…,an​, indicating the initial list.

Next qq line, one operation per line. The ii-th line could be 3 integers (1,l_i,r_i1,li​,ri​), indicating the first type operation, or 2 integers (2,x_i2,xi​), indicating the second type operation.

1\le T \le 10,1≤T≤10, 1\le n,q\le 10^5,1≤n,q≤105, 1\le a_i\le 10^9,1≤ai​≤109, \sum n \le 10^5,∑n≤105, \sum q \le 10^5,∑q≤105, 1\le x_i,l_i,r_i \le n,1≤xi​,li​,ri​≤n, the sum of the number of first type operations (all test cases together) not exceeds 2000020000.

Output

For each test case, print one line, indicating the xor sum of the answers.

题意:有一个长度为n的数组,然后有两个操作,操作1 l r是将lr这段数复制之后加在r后,操作2 x是找位于x的数的所有异或和

思路:将lr这段复制加在r后面相当于加了长度为(r-l+1)的数让r后面的数往后了,所以变化后的r后面的数是原来数组里的数往后推了(l-r+1)个,那么我们找变化后的r后面的数ai实际上就是他前面的第r-l+1个数,即变化后的数组里的a[i]=变化前的数里的a[i-(r-l+1)],然后我们可以从后往前遍历数组让r+1~n的数ai全是a[i-(r-l+1)],就完成了每次的复制。

/*

 .----------------.  .----------------.  .----------------.  .----------------. 
| .--------------. || .--------------. || .--------------. || .--------------. |
| |  ________    | || |  _________   | || | ____    ____ | || |     ____     | |
| | |_   ___ `.  | || | |_   ___  |  | || ||_   \  /   _|| || |   .'    `.   | |
| |   | |   `. \ | || |   | |_  \_|  | || |  |   \/   |  | || |  /  .--.  \  | |
| |   | |    | | | || |   |  _|  _   | || |  | |\  /| |  | || |  | |    | |  | |
| |  _| |___.' / | || |  _| |___/ |  | || | _| |_\/_| |_ | || |  \  `--'  /  | |
| | |________.'  | || | |_________|  | || ||_____||_____|| || |   `.____.'   | |
| |              | || |              | || |              | || |              | |
| '--------------' || '--------------' || '--------------' || '--------------' |
 '----------------'  '----------------'  '----------------'  '----------------'

*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b){
	return b>0 ? gcd(b,a%b):a;
}
const int N=1e5+10;
int n,q;
int a[N];
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
void sove(){
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int con=0;
	while(q--){
		int op;
		cin>>op;
		if(op==1){
			int l,r;
			cin>>l>>r;
			for(int i=n;i>=r+1;i--){
				a[i]=a[i-(r-l+1)];
			}
		}else{
			int x;
			cin>>x;
			con^=a[x];
		}
	}
	cout<<con<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie() ,cout.tie() ;
	int t=1;
	cin>>t;
	while(t--){
		sove();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值