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的更多相关文章
随机推荐
- ideaui安装破解、相关配置、JRebel破解
前言: Ideaui 2019(官网 https://www.jetbrains.com/idea/?fromMenu) 安装软件就简单啦,下载选择路径就完事了,注意文件名全英文: 但是按照咱们传 ...
- python3 内置方法 字符串转换为字典
内置方法:eval()将字符串转换为字典代码: str = '''{'backend':'www.oldboy.org', 'record':{ 'server':'122.111.2.23', 'w ...
- javascript之typeof
定义和用法
- Consul基本使用
原文: Consul基本使用 date: 2019-05-13 17:01:37 前言 官网介绍Consul是一个分布式服务网格(Service Mesh)解决方案... 而我目前的理解是提供了分布式 ...
- jacascript Ajax 学习之 JQuery-Ajax
jQuery 对 ajax 操作进行了封装,在 jQuery 中 $.ajax() 属性最底层的方法,第2层是 load().$.get() 和 $.post() 方法,第3层是 $.getScrip ...
- 线程二(Monitor)
Monitor 类的命名空间是 System.Threading,它的用法和 lock 本质是一样的. 使用 Monitor 类锁定资源的代码如下. Monitor.Enter(object); tr ...
- iOS-CGContextRef
图形上下文(Graphics Context)---绘制目标 需要在iOS应用程序的屏幕上进行绘制时,需要先定义一个UIView类,并实现它的drawRect:方法,当启动程序时,会先调用loadVi ...
- Vue动画操作
概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.c ...
- py-2 python介绍与安装
一.python介绍 1.python背景 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,Guido开始写能够解释Python语言语法的解释器.Py ...
- Scala 中 call by name & call by value 的区别
call by value:会先计算参数的值,然后再传递给被调用的函数 call by name:参数会到实际使用的时候才计算 定义方法 def return1():Int = { println(& ...