【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 ...
随机推荐
- IP的面向无连接状态
ip是面向于无连接的状态,在发包前,不需要建立与对端目标地址之间的连接. ip采用面向无连接的原因? 面向连接比无连接复杂,此外每次通信前都要事先建立连接,会降低处理速度.需要有连接时可以委托上一层提 ...
- 建立live555海思编码推流服务
因项目需要,这一周弄了一下live555.需求:海思编码——>RTSP server,使用VLC可以访问,类似于网络摄像机的需求.看了一下,live555的架构太复杂了,半桶水的C++水平还真的 ...
- matlab——之class类(详细总结)
https://blog.csdn.net/qinze5857/article/details/80545885 开篇:搜了一下网上介绍matlab的class类,信息不全,且总结不全面,于是单独he ...
- java代码审计中的一些常见漏洞及其特征函数
文章来源:https://xz.aliyun.com/t/1633 最近在先知上看到之前有篇关于java代码审计的文章总结的蛮好,记录以下特征函数,方便查阅,同时自己也会将在平时代码审计过程中积累的函 ...
- G面经Prepare: Longest All One Substring
give a string, all 1 or 0, we can flip a 0 to 1, find the longest 1 substring after the flipping 这是一 ...
- Leetcode: Sliding Window Median
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- 蓝桥杯近3年决赛题之二(16年b组)
做的时候只做对了第一题. 1. 一步之遥 从昏迷中醒来,小明发现自己被关在X星球的废矿车里.矿车停在平直的废弃的轨道上.他的面前是两个按钮,分别写着“F”和“B”. 小明突然记起来,这两个按钮可以控制 ...
- wangEditor编辑器 Vue基本配置项
wangEditor编辑器 Vue基本配置项 1.Vue安装方法 npm i wangeditor -S <template> <div id='wangeditor'> &l ...
- (.NET高级课程笔记)Lambd、Linq总结
知识总结 1.委托简介:委托是一种类型,可以写在类里,也可以写在类外面,级别和类一样高. 2.匿名方法.匿名类 3.Lambda表达式:goes to 4.系统自带委托:Func/Action 5.扩 ...
- 【JavaScript】第8章读书笔记
本章常用的DOM方法 切记,页面的逻辑是:创建新的元素,给新的元素创建内容,通过appendChild把新元素的内容插入到新元素节点中:通过appendChild把新元素插入到已有元素节点中 书上的老 ...