当前位置:网站首页>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;
}
边栏推荐
- 论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》
- The second day HCIP
- 【ROS基础】map、odom、base_link、laser 的理解 及其 tf 树的理解
- Expert Insights | 3 ways to seize innovation opportunities in a downturn
- “蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
- CSRF-跨站请求伪造-相关知识
- (Notes are not completed) [Graph Theory] Traversal of graphs
- 【红队】ATT&CK - 创建或修改系统进程实现持久化(更新ing)
- 交换部分 VLAN
- PHP Warning: putenv() has been disabled for security reasons in phar
猜你喜欢
【请教】SQL语句按列1去重来计算列2之和
交换部分 VLAN
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
About the local server problem after ue4.27 pixel streaming package
PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
宝塔+FastAdmin 404 Not Found
交换--STP协议
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
随机推荐
请教一下,Flink SQL ,JDBC sink 入 mysql 库,想要搞一个自增主键,要怎么写
入门opencv,欢笑快乐每一天
封装class类一次性解决全屏问题
【机器学习】实验2布置:基于回归分析的大学综合得分预测
跨阻放大器
海缆探测仪TSS350(二)
线程的创建方式
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
【暑期每日一题】洛谷 P1255 数楼梯
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
File upload vulnerability (2)
July 18-July 31, 2022 (Ue4 video tutorials and documentation, 20 hours. Total 1412 hours, 8588 hours left)
【论文精读】Geometric Structure Preserving Warp for Natural Image Stitching
MQ带来的一些问题、及解决方案
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
【机器学习】实验5布置:AAAI会议论文聚类分析
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
(部分不懂,笔记整理未完成)【图论】差分约束