题意:

$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的更多相关文章

随机推荐

  1. IIS不能下载config配置文件的解决方法

    之前作程序升级的时候,需要从服务端下载后缀为config的配置文件,结果程序抛出404异常.后来百度才知道,是IIS禁止下载config文件的原因.在这里记录一下解决方法. 在我的电脑,右键管理,打开 ...

  2. C++ 去掉字符串的首尾空格和全部空格

    #include <iostream>#include <string>using namespace std; //去掉收尾空格string& ClearHeadTa ...

  3. python——操作系统的发展史

    一.手工操作 —— 穿孔卡片 1946年第一台计算机诞生--20世纪50年代中期,计算机工作还在采用手工操作方式.此时还没有操作系统的概念.    程序员将对应于程序和数据的已穿孔的纸带(或卡片)装入 ...

  4. 六、eureka客户端自动注册服务

    所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 上一篇文章,我们稍微了解了一下eureka客户端是如何自动配置的,配置了哪些东西.在自动 ...

  5. Linux查找文件之Find命令

    Linux系统文件中常用属性包括以下内容:名称,大小,权限,属主,属组,修改时间,访问时间等.在庞大的Linux系统中查询文件,需要借助查找工具来实现,依此可以查询相同或指定属性的文件,本文所讲的查询 ...

  6. 【日语】【ZZ】日语人称小结

    [ZZ]日语人称小结 日语中有关人称的词很多,也有不少朋友问 现整理了一下,希望能对那些不太清楚的朋友有点帮助 如果您认为在下有写错的地方,或者您有什么高见,请不吝赐教 第一人称 “我” 1.私 わた ...

  7. iOS Touch Id 开发

    Touch Id Touch Id是iPhone5S后加入的一项新的功能,也就是大家熟知的指纹识别技术.大家用得最多的可能是手机的解屏操作,不用在和以前一样输入手机的四位数密码进行验证.一方面不用担心 ...

  8. angular2-cli 环境搭建

    开发工具:windows ,Vscode, npm, 前提:安装nodejs nodejs 模块全局安装路径配置:http://www.cnblogs.com/rancho-blog/p/656792 ...

  9. shell 函数的高级用法

    函数介绍 linux shell中的函数和大多数编程语言中的函数一样 将相似的任务或者代码封装到函数中,供其他地方调用 语法格式 如何调用函数 shell终端中定义函数 [root@master da ...

  10. Vue路由的使用和route-link router-view样式和动画的设置

    什么是路由 后端路由:**对于普通的网站,所有的超链接都是URL地址,所有的URL地址都对应服务器上对应的资源: 前端路由:**对于单页面应用程序来说,主要通过URL中的hash(#号)来实现不同页面 ...