当前位置:网站首页>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;
}
边栏推荐
- Clapper that can interact with the audience in real time
- 你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
- Project development specification
- 跨阻放大器
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- 数据库概论-MySQL的数据表的基本操作
- Gradle系列——Gradle插件(基于Gradle文档7.5)day3-2
- (Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
- docker 安装mysql
- 队列题目:无法吃午餐的学生数量
猜你喜欢
随机推荐
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
【图像去噪】基于matlab双立方插值和稀疏表示图像去噪【含Matlab源码 2009期】
跨阻放大器
打卡day05
The second day HCIP
【红队】ATT&CK - 创建或修改系统进程实现持久化(更新ing)
Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
2020美亚团队赛复盘
第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
速看!PMP新考纲、PMBOK第七版解读
【机器学习】课程设计布置:某闯关类手游用户流失预测
PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
【暑期每日一题】洛谷 P1192 台阶问题
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
File upload vulnerability (2)
实例026:递归求阶乘









