cf242 E
题意:
$n$ 个数 $a_i$,
两种询问
$1, l, r$ 查询 $[l, r]$ 的和
$2, l, r, x$ 将区间 $[l, r]$ 所有数异或 $x$
建立 $30$ 课线段树
第 $i$ 颗线段树维护所有 $a$ 二进制的第 $i$ 为上的数字 $0, 1$
异或操作分别以 $x$ 的二进制相应位异或相应线段树
可见只有当 $x$ 的二进制位为 $1$ 是操作有效
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std; #define LL long long #define gc getchar()
inline int read() {int x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
inline LL read_LL() {LL x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
#undef gc const int N = 1e5 + ; int Size[N << ];
int n, m, Ans; #define lson jd << 1
#define rson jd << 1 | 1 struct Node {
int W[N << ], F[N << ]; void Push_down(int jd) {
F[lson] ^= , F[rson] ^= ;
W[lson] = Size[lson] - W[lson];
W[rson] = Size[rson] - W[rson];
F[jd] = ;
} void Push_up(int jd) {
W[jd] = W[lson] + W[rson];
} void Sec_G(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) {
F[jd] ^= ;
W[jd] = Size[jd] - W[jd];
return ;
}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y);
if(y > mid ) Sec_G(mid + , r, rson, x, y);
Push_up(jd);
} void Sec_A(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) {
Ans += W[jd];
return ;
}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, lson, x, y);
if(y > mid) Sec_A(mid + , r, rson, x, y);
}
} Tree[]; void Build_tree(int l, int r, int jd) {
Size[jd] = r - l + ;
if(l == r) {
int x = read();
for(int i = ; ( << i) <= x; i ++) {
Tree[i + ].W[jd] = (bool) (( << i) & x);
}
return ;
}
int mid = (l + r) >> ;
Build_tree(l, mid, lson), Build_tree(mid + , r, rson);
for(int i = ; i <= ; i ++) {
Tree[i].W[jd] = Tree[i].W[lson] + Tree[i].W[rson];
}
} int main() {
n = read();
Build_tree(, n, );
m = read();
for(; m; m --) {
int opt = read(), l = read(), r = read();
if(opt == ) {
int x = read();
for(int i = ; ( << i) <= x; i ++) {
if((( << i) & x)) {
Tree[i + ].Sec_G(, n, , l, r);
}
}
} else {
LL Answer = ;
for(int i = ; i <= ; i ++) {
Ans = ;
Tree[i].Sec_A(, n, , l, r);
Answer += (1ll * Ans * (LL) pow(, i - ));
}
cout << Answer << "\n";
}
} return ;
}
cf242 E的更多相关文章
随机推荐
- JAVA堆,栈的区别,用AarrayList、LinkedList自定义栈
大家都知道java模拟机在运行时要开辟空间所以它有特定的五个内存划分: 1.寄存器: 2.本地方法区: 3.方法区: 4.栈内存: 5.堆内存: 但是我们今天来注重讲一下栈和堆 ...
- react实现设置答题器选项个数
一,设置答题器选项import React, { useState, useEffect } from 'react' import PropTypes from 'prop-types' impor ...
- DO、VO、DTO 区别
DTO:数据传输对象,主要用于外部接口参数传递封装,接口与接口进行传递使用. VO:视图对象,主要用于给前端返回页面参数使用. DO:数据对象,主要用于数据库层传递. DTO转DO:接口接收参数将参数 ...
- linux 设置用户组共享文件
1.首先建立一个名为workgroup的用户组,然后向用户组里面添加两名用户 tom 和liming,并为其设置密码 sudo groupadd workgroup [sudo] lcy 的密码: s ...
- hibernate注解(自动建表如何有表DDL注释) -- Comment用法
import java.io.Serializable; import java.sql.Date; import java.sql.Timestamp; import javax.persisten ...
- 我们为什么要用redis
Redis的5要点: 1.为什么要选择Redis:介绍Redis的使用场景与使用Redis的原因: 2.Redis常用命令总结:包括时间复杂度总结与具体数据类型在Redis内部使用的数据结构: 3.R ...
- 一个让Java事半功倍的反射库
在Java和Android中,我们常常会使用反射来达到一些兼容的目的.Java原生提供的反射很是麻烦,使用起来很是不方便.比如我们想要调UserManager的静态方法get,使用原生的实现如下 tr ...
- MySQL常见interview
mysql支持的存储引擎,以及各自区别 常用的有myisam,innodb,bdb myisam是mysql默认存储引擎:不支持事务和外键,访问速度快,对事物完整性没有要求或者以select.inse ...
- Flutter——TextField组件(文本框组件)
TextField组件的常用属性: 属性 描述 maxLines 设置此参数可以把文本框改为多行文本框 onChanged 文本框改变的时候触发的事件 decoration hintText 类似 h ...
- SUSE Ceph RBD Mirror - Storage 6
Ceph采用的是强一致性同步模型,所有副本都必须完成写操作才算一次写入成功,这就导致不能很好地支持跨域部署,因为如果副本在异地,网络延迟就会很大,拖垮整个集群的写性能.因此,Ceph集群很少有跨域部署 ...