【原题题面】传送门

【题面翻译】传送门

【解题思路】

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

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

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. Windows下使用TeamViewer连接远程服务器,以及解决“远程桌面关闭后TeamViewer不能连接”的问题

    1.本地安装TeamViewer,完成后如下: 2.远程服务器也安装TeamViewer 在本地TeamViewer中得伙伴ID,输入远程的ID,弹出如下对话框,输入密码即可. 3.这时虽然可以连接, ...

  2. 配置环境变量及jdk

    1.配置虚拟机nat默认为yes:cd  /etc/sysconfig/network-scripts/    ll(查看下面ifcfg文件名称)    vim ifcfg-eno16777736(按 ...

  3. 小程序开发 easy-less 配置

    开发支付宝小程序, 不习惯直接写css 了,推动小程序的开发太低效,讲道理默认构建就应该支持less 和sass. vscode  有easy-less 插件,看下配置支持自定义扩展名. { &quo ...

  4. spring-boot war包

    接着上面的spring-boot项目,直接使用jar包方便调试,在开发阶段非常方便,生产上最好打成war形式 要想spring-boot打war包,还是从pom.xml入手 1.1 调整pom.xml ...

  5. oracle储存过程学习笔记

    转载至: https://www.2cto.com/database/201610/559389.htm 1.什么是oracle存储过程 存储过程和函数也是一种PL/SQL块,是存入数据库的PL/SQ ...

  6. Random-Forest-Python

    1. 近期目标,实现随机森林进行点云分类 1)学习阶段: [干货]Kaggle 数据挖掘比赛经验分享 Kaggle Machine Learning Competition: Predicting T ...

  7. python报错记录

    1.AttributeError: 'NoneType' object has no attribute 'group' import re s=r'<title>kobe<\tit ...

  8. Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor

    Newtonsoft.Json DeserializeObject 反序列化  IdentityServer4.Models Cliecnt 错误: Newtonsoft.Json.JsonSeria ...

  9. Oracle VM Virtual 安装 ubuntu 后设置全屏

    按照正常流程在vm中安装了ubuntu之后,发现ubuntu系统无法全屏显示,解决途径如下: 1.在vm中点击设置 2.选择“安装增强功能” 3.正常情况下,我们可以在桌面看到一个光盘图标(文件名:V ...

  10. 自己绘制table,加分页