题意:

$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. java redisUtils工具类很全

    GitHub地址:https://github.com/whvcse/RedisUtil redisUtils工具类: package com.citydo.utils; import org.spr ...

  2. 通透理解viewport

    摘自:https://blog.csdn.net/u014787301/article/details/44466697 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewpor ...

  3. php权限管理

    首先权限管理肯定是需要登陆的,这里就简单的写一个登陆页面. 简单的登陆页面login.php <h1>登录页面</h1> <form action="login ...

  4. 【日语】日语N5学习

    副词与连接词 ~から: 从-(表示时间.场所起点) ~まで: 到-(表示时间.场所终点) と: 和(并列时用) えーと: 嗯 いっしょに: 一起 ちょっと: 一点儿 いつも: 经常.总是 ときどき: ...

  5. 在浏览器中输入www.taobao.com后执行的全部过程

    >>>点击网址后,应用层的DNS协议会将网址解析为IP地址: DNS查找过程: 1.        浏览器会检查缓存中有没有这个域名对应的解析过的IP地址,如果缓存中有,这个解析过程 ...

  6. c# try 和 catch 块

  7. 分布式session的几种实现方式

    在搭建完集群环境后,不得不考虑的一个问题就是用户访问产生的session如何处理.如果不做任何处理的话,用户将出现频繁登录的现象,比如集群中存在A.B两台服务器,用户在第一次访问网站时,Nginx通过 ...

  8. python词云图之WordCloud

    1. 导入需要的包package import matplotlib.pyplot as plt from scipy.misc import imread from wordcloud import ...

  9. Song Form

    First of all, song form is an indepentent concept from the boxes, boxes simply describe the way the ...

  10. Luogu P1062 数列

    Luogu P1062 数列 题目说: 把所有$k$的方幂及所有有限个互不相等的$k$的方幂之和构成一个递增的序列. 这就是说,每一个$k$的方幂只能有或没有. 有为$0$,没有为$1$. 所以这些数 ...