当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Splunk Field Caculated 计算字段

【请教】SQL语句按列1去重来计算列2之和

MySQL-底层设置

(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)

Azure Synapse Analytics上创建用户并赋予权限

机器学习笔记--数学库

MySQL-基础

Compact格式下MySQL的数据如何存储到磁盘
![The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]](/img/14/cd6ed7452230571db2e027f61dbdba.png)
The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]

雷达人体存在感应器方案,智能物联网感知技术,实时感应人体存在
随机推荐
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
From cloud computing to function computing
OC-NSDictionary
MySQL-数据库设计规范
OC-NSString
LeetCode SQL 197. 上升的温度
Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)
Please tell me, how to write Flink SQL and JDBC sink into mysql library and want to create an auto-incrementing primary key
Data reveal that the average cost is as high as $4.35 million in 2022, a record!
FormData上传二进制文件、对象、对象数组
查看端口号占用
MySQL批量更新
Find the largest n files
Go implements distributed locks
MySQL-索引详解
OC-error prompt
OC-错误提示
spark read folder data
LeetCode刷题(7)