【codeforces 242E】XOR on Segment
【原题题面】传送门
【题面翻译】传送门
【解题思路】
操作涉及到区间求和和区间异或,考虑到异或操作,我们对每个数二进制分解。
把每一位单独提出来做,异或要么取反要么变为不变,对于每一位建一颗线段树,那么原题中的信息维护就相当于:
1.区间取反
2.区间求和
那就打标记传标记好了。。
【code】
#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,q,abt,x,y,z;
int a[][N];
int d[][N<<];
long long t[][N<<],ans;
inline int read(){
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-''; ch=getchar();}
return x*f;
}
#define ls p<<1
#define rs p<<1|1 inline void B(int l,int r,int p,int k)
{
if(l==r){t[k][p]=a[k][l];return;}
int m=l+r>>;
B(l,m,ls,k),B(m+,r,rs,k);
t[k][p]=t[k][ls]+t[k][rs];
} inline void U(int l,int r,int p,int k)
{
if(x<=l&&r<=y){t[k][p]=(r-l+)-t[k][p],d[k][p]^=;return;}
int m=l+r>>;
if(d[k][p])
{
t[k][ls]=(m-l+)-t[k][ls],d[k][ls]^=;
t[k][rs]=(r-m)-t[k][rs],d[k][rs]^=;
d[k][p]=;
}
if(x<=m)U(l,m,ls,k);
if(y>m)U(m+,r,rs,k);
t[k][p]=t[k][ls]+t[k][rs];
} inline long long A(int l,int r,int p,int k)
{
if(x<=l&&r<=y)return t[k][p];
int m=l+r>>;
if(d[k][p])
{
t[k][ls]=(m-l+)-t[k][ls],d[k][ls]^=;
t[k][rs]=(r-m)-t[k][rs],d[k][rs]^=;
d[k][p]=;
}
long long as=;
if(x<=m)as+=A(l,m,ls,k);
if(y>m)as+=A(m+,r,rs,k);
return as;
} int main()
{
n=read();
for(int i=;i<=n;++i)
{
z=read();
for(int j=;j<=;++j)
{
if(z&)a[j][i]=;
z>>=;
}
}
for(int i=;i<=;++i)B(,n,,i); q=read();
for(int i=;i<=q;++i)
{
abt=read(),x=read(),y=read();
if(abt==)
{
ans=;
for(int j=;j;--j)ans=ans*+A(,n,,j);
printf("%lld\n",ans);
}
else
{
z=read();
for(int j=;j<=;++j)
{
if(z&)U(,n,,j);
z>>=;
}
}
} return ;
}
【codeforces 242E】XOR on Segment的更多相关文章
- 【第400篇题解纪念2016年10月28日】【28.10%】【codeforces 617E】XOR and Favorite Number
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- 【CodeForces 616D】Longest k-Good Segment
题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 766E】Mahmoud and a xor trip
[题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【19.46%】【codeforces 551B】ZgukistringZ
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Eclipse中STM32工程建立步骤
前段时间一直在折腾linux系统上STM32的开发,网上一顿搜,费劲九牛二虎之力终于把环境搭好了(现在都有点忘了,后面再折腾环境搭建一定要写个教程,今天先不写了). 自从环境搭好之后,就基本抛弃MDK ...
- 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165317
第一周作业 Kali的安装 Kali的下载 从kali官网下载kali-linux 64-bit 版本. Kali的安装 由于在娄老师的课上使用virtualbox, 所以我习惯性使用virtual ...
- scrapy学习笔记(1)
初探scrapy,发现很多入门教程对应的网址都失效或者改变布局了,走了很多弯路.于是自己摸索做一个笔记. 环境是win10 python3.6(anaconda). 安装 pip install sc ...
- Cron表达式范例
每隔5秒执行一次:*/5 * * * * ? 每隔1分钟执行一次:0 */1 * * * ? 每天23点执行一次:0 0 23 * * ? 每天凌晨1点执行一次:0 0 1 * * ? 每月1号凌晨1 ...
- java中的类型转换
java中的类型转换分为两种 自动类型转换 要实现数据的自动类型转换必须同时满足下面两个条件 两种数据类型彼此兼容 目标类型的取值范围大于原类型范围 强制类型转换 当两种数据类型彼此不兼容,或者说目标 ...
- Kafka笔记5(内部工作原理)
集群成员关系: Kafka使用zookeeper维护集群成员信息,每个broker拥有唯一标识符,这个标识符可以在配置文件里指定也可以自动生成,会注册到Zookeeper的/brokers/ids路径 ...
- c# 中HttpClient访问Https网站
c# 中HttpClient访问Https网站,加入如下代码: handler = new HttpClientHandler() ;handler.AllowAutoRedirect = true; ...
- mac 配置vue+sanic环境准备工作
Vue用到npm/cnpm.webpack ,准备工作主要是将这些安装上. 首先安装这些最好使用root用户. 第一步安装npm:npm是node.js的一部分,所以需要安装node.js. 安装no ...
- html5 css练习浮动布局
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- C# 链表去重 List 一维 二维 分别使用 Distinct() GroupBy() 方法
分别使用List中Distinct(),GroupBy()实现链表的去重. 1.先上效果: 一维链表中分别有元素“aa”,"bb",'aa','aa',"cc" ...