当前位置:网站首页>hdu1752 copy
hdu1752 copy
2022-08-02 06:46:00 【doctorZ_】
题目大意
给你一个整数序列 { a n } \{a_n\} { an},有两种操作,将执行 q q q次操作,第一种把 l ∼ r l\sim r l∼r的序列 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,q≤1e5,l,r,x≤n
题解
第一种操作对后续询问的影响,如果 x ≤ r x\le r x≤r则不变, x > r x>r x>r则 x = x − ( r − l + 1 ) x=x-(r-l+1) x=x−(r−l+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;
}
边栏推荐
- 队列题目:无法吃午餐的学生数量
- FaceBook社媒营销高效转化技巧分享
- [21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
- SQL执行顺序
- Clapper that can interact with the audience in real time
- 59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
- PMP新考纲通关秘籍,告别抓瞎
- Servlet
- About the local server problem after ue4.27 pixel streaming package
- 2022.07.31(LC_6132_使数组中所有元素都等于零)
猜你喜欢
随机推荐
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
[Dataset][VOC] Eyewear dataset 6000 in VOC format
交换部分 VLAN
跨阻放大器
暑期总结(三)
mysql 注入
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
typescript 'props' is declared but its value is never read solution
【机器学习】实验4布置:AAAI会议论文聚类分析
深度学习网络模型的改进与调整
The nacos source code can not find the istio package
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
倍福使用AdsRemote组件实现和C#的ADS通讯
.NET Static Code Weaving - Rougamo Release 1.1.0
有趣的网站
About the local server problem after ue4.27 pixel streaming package
技术管理三级跳
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
Two good php debug tutorials
(Notes are not completed) [Graph Theory] Traversal of graphs