【原题题面】传送门

【题面翻译】传送门

【解题思路】

操作涉及到区间求和和区间异或,考虑到异或操作,我们对每个数二进制分解。

把每一位单独提出来做,异或要么取反要么变为不变,对于每一位建一颗线段树,那么原题中的信息维护就相当于:

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

  1. 【第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 ...

  2. Codeforces 242E:XOR on Segment(位上的线段树)

    http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...

  3. 【CodeForces 616D】Longest k-Good Segment

    题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 766E】Mahmoud and a xor trip

    [题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...

  6. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【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 ...

  8. 【19.46%】【codeforces 551B】ZgukistringZ

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 755D】PolandBall and Polygon

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. VS2017 SVN插件-AnkhSVN

    AnkhSVN 该插件可以直接在vs017扩展和工具里安装,安装完成即可使用 默认VS自带的源码管理工具是GIT 如果已经使用需要手动切换到SVN:工具==>选项菜单中设置 SVN使用方法: 1 ...

  2. Luogu5155 [USACO18DEC]Balance Beam

    题目链接:洛谷 这道题看起来是个期望题,但是其实是一道计算几何(这种题太妙了) 首先有一个很好的结论,在一个长度为$L$的数轴上,每次从$x$处出发,不停地走,有$\frac{x}{L}$的概率从右端 ...

  3. CF1093F Vasya and Array

    题目链接:洛谷 以后还是要多打CF,不然就会错过这些很好的思维题了.我dp学得还是太烂,要多总结. 首先$len=1$就直接输出0. 我们考虑$dp[i][j]$表示前$i$个数的答案,而且第$i$个 ...

  4. instrument 之 core animation

    1.Color Blended Layers 图层混合 需要消耗一定的GPU资源,避免设置alpha小于1,省去不必要的运算 2.Color Hits Green and Misses Red 光栅化 ...

  5. Mysql集群原理

    一. 主从复制概述  在实际生产中,数据的重要性不言而喻,提供安全可靠的数据保障是技术与运维部门的职责所在:如果我们的数据库只有一台服务器,那么很容易产生单点故障的问题,比如这台服务器访问压力过大而没 ...

  6. 立一个Flag吧

    以后在学习上遇到的问题以及解决办法,大部分都要记录在这里了,以备温故知新....就这样吧!

  7. 做一个有产品思维的研发:部署(Tomcat配置,Nginx配置,JDK配置)

    每天10分钟,解决一个研发问题. 如果你想了解我在做什么,请看<做一个有产品思维的研发:课程大纲>传送门:https://www.cnblogs.com/hunttown/p/104909 ...

  8. OO第一单元表达式求导作业总结

    第一次作业 功能描述: 对输入的表达式进行求导计算和格式正误判断   思路: 一开始的想法是想写一个大正则找到一个通项式,通过这个多项式来判断WRONG FORMAT,结果发现正则写的总是不完善,会漏 ...

  9. Cocos Creator (webgl模式下怎么让canvas背景透明)

    项目中构建出web-mobile包后,打开main.js 在main.js中加入如下两行即可让canvas变透明 cc.director.setClearColor(new cc.Color(0,0, ...

  10. TP5新增模块

    tp5模块自动生成 1build.php配置要生成的目录 <?php// +----------------------------------------------------------- ...