hdu1752 copy

题目大意

给你一个整数序列 { a n } \{a_n\} {an},有两种操作,将执行 q q q次操作,第一种把 l ∼ r l\sim r lr的序列 c o p y copy copy一份插到 r r r后,第二种询问 a x a_x ax是什么,要求求出所有 2 2 2操作的异或和
n , q ≤ 1 e 5 , l , r , x ≤ n n,q\le 1e5,l,r,x\le n n,q1e5,l,r,xn

题解

第一种操作对后续询问的影响,如果 x ≤ r x\le r xr则不变, x > r x>r x>r x = x − ( r − l + 1 ) x=x-(r-l+1) x=x(rl+1)
所以可以考虑从后往前进行操作,但是还是不好做
由于答案要求异或和,所以相同询问可以抵消,所以可以用 b i t s e t bitset bitset维护,第一种操作也可以很轻松地用 b i t s e t bitset bitset实现

code

#include<cstdio>
#include<bitset>
#include<iostream>
using namespace std;
void read(int &res)
{
	res=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
}
const int N=1e5;
int n,q,a[N+10],opt[N+10],x[N+10],y[N+10];
bitset<N> dp,low,high;
int main()
{
	int T;
	read(T);
	for(;T--;)
	{
		read(n),read(q);
		for(int i=0;i<n;i++) read(a[i]);
		for(int i=1;i<=q;i++)
		{
			read(opt[i]),read(x[i]);
			if(opt[i]==1) read(y[i]);
			x[i]--,y[i]--; 
		}
		dp.reset();
		for(int i=q;i>=1;i--)
		{
			if(opt[i]==1) high=dp>>y[i]+1,low=dp<<N-y[i]-1>>N-y[i]-1,dp=low^(high<<x[i]);
			else dp.flip(x[i]);
		}
		int ans=0;
		for(int i=0;i<n;i++) if(dp[i]) ans^=a[i];
		printf("%d\n",ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值