当前位置:网站首页>hdu1752 copy
hdu1752 copy
2022-08-02 07:54:00 【doctorZ_】
题目大意
给你一个整数序列 { a n } \{a_n\} { an},有两种操作,将执行 q q q次操作,第一种把 l ∼ r l\sim r l∼r的序列 c o p y copy copyone insert r r r后,第二种询问 a x a_x ax是什么,要求求出所有 2 2 2XOR and sum of operations
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
题解
The effect of the first operation on subsequent queries,如果 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)
So you can consider working from the back to the front,But still not good
Since the answer asks for XOR and,So the same query can cancel,所以可以用 b i t s e t bitset bitset维护,The first operation can also be used easily 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;
}
边栏推荐
- Install Metasploitable2 on VMware
- LeetCode SQL 197. 上升的温度
- MySQL-执行流程+缓存+存储引擎
- Chain Of Responsibility
- 论文阅读 (64):Weakly-supervised Video Anomaly Detection with Robust Temporal Feature Magnitude Learning
- MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- apt & apt-get commands
- 自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
- 概率论与数理统计
- SQL server 2014 怎么一次性导出多个查询结果?
猜你喜欢
随机推荐
A Preliminary Study on the Basic Principles of Formal Methods
Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
MySQL-FlinkCDC-Hudi实时入湖
主流定时任务解决方案全横评
跨阻放大器
regular expression
使用hutool做本地缓存的工具类
埋点开发流程
apt & apt-get commands
mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
图腾柱和推挽电路介绍
LeetCode 2360. The longest cycle in a graph
OC-NSArray
查找最大的n个文件
【ROS基础】rosbag 的使用方法
Metasploit(MSF)基础超级详细版
在VMware上安装Metasploitable2
LeetCode Algorithm 1374. 生成每种字符都是奇数个的字符串
查看端口号占用
Splunk Field Caculated Calculated Field