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的更多相关文章
随机推荐
- springboot调用mongo
目录 添加 删除 文档操作更新 简单聚合操作 count, distinct 普通查询 分组 group Aggregate mapReduce 分页查询 文件上传 文件下载 随便测试了一下,有问题请 ...
- nodejs模块fs——文件操作api
// fs模块常用api // 读取文件 .写入文件 .追加文件. 拷贝文件 .删除文件 // 读取文件 // fs.readFile(path[, options], callback) // fs ...
- stdmap 用 at() 取值,如果 key 不存在,不好意思,程序崩溃。QMap 用 value()取值,如果 key 不存在,不会崩溃,你还可以指定默认值
我觉得 Qt6 最应该升级的是容器类 stdmap 在遍历的时候,同时获取 key 与 value 非常方便: for(auto& var:map){ qDebug()<<v ...
- es6☞对象的解构赋值
变量必须与属性同名 let {name, age} = {name: 'wang', age: 22}; console.log(name, age); //wang 22 let {name} = ...
- 前端开发 Vue -4promise解读1
JS(JavaScript) - Promise 2015年6月, ES2015(即 ECMAScript 6.ES6) 正式发布.其中 Promise 被列为正式规范,成为 ES6 中最重要的特性之 ...
- 解决在web.xml中配置server服务器启动失败问题
一.问题"Server Tomacat v8.5 Server at locallhost failed to start" 二.解决方法:删除注释@webServlet 三.分析 ...
- fastjson反序列化漏洞研究(上)
前言 最近护网期间,又听说fastjson传出“0day”,但网上并没有预警,在github上fastjson库中也有人提问关于fastjson反序列化漏洞的详情.也有人说是可能出现了新的绕过方式.不 ...
- S5PV210 时钟
CLOCK DOMAINS 时钟域 S5PV210 consists of three clock domains, namely, main system (MSYS), display syste ...
- 关于MUI页面之间传值以及刷新的问题
一.页面刷新问题 1.父页面A跳转到子页面B,B页面修改数据后再跳回A页面,刷新A页面数据 (1).父页面A代码 window.addEventListener("pageflowrefre ...
- Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
今天想把之前的一个demo用Nginx把资源分离开来,在网上看了一天,整整弄了一天,硬是没弄出来. 要么全是同样的内容的,要么就是环境跟我这里不一样的.再加上对Nginx没接触过,给我都整哭了差点. ...