【原题题面】传送门

【题面翻译】传送门

【解题思路】

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

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

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. Enterprise Architect

    Enterprise Architect 是一款计算机辅助软件工程,这款软件用于设计和构建软件系统.业务流程建模及更多通用的建模.EA不同于普通的UML画图工具(如VISIO),它将支撑系统开发的全过 ...

  2. mysql GROUP_CONCAT 查询某个字段(查询结果默认逗号拼接)

    Mysql 的 GROUP_CONCAT 函数默认将查询的结果用逗号拼接并返回一个字符串,如:李四,long,张三 1. 常用方式 select GROUP_CONCAT(user_name) use ...

  3. linux /proc/sys/vm/中各个文件含义

    1)      /proc/sys/vm/block_dump该文件表示是否打开Block Debug模式,用于记录所有的读写及Dirty Block写回动作. 缺省设置:0,禁用Block Debu ...

  4. springboot+spring security +oauth2.0 demo搭建(password模式)(认证授权端与资源服务端分离的形式)

    项目security_simple(认证授权项目) 1.新建springboot项目 这儿选择springboot版本我选择的是2.0.6 点击finish后完成项目的创建 2.引入maven依赖  ...

  5. Oracle控制文件冗余

    1.备份参数文件.检查控制文件.检查磁盘组名 sqlplus / as sysdba !echo "create pfile='$HOME/pfile_$ORACLE_SID_`date + ...

  6. Repeater 实现 OnSelectedIndexChanged

    在Repeater中使用DropDownList的方法   在Repeater中使用DropDownList的方法 以下代码并不完整,只记录了关键的方法 aspx代码中 假设这是一个用户管理的系统的模 ...

  7. setup FTP server on CentOS 7

    Setup FTP Server on CentOS 7 Install vsftpd vsftpd (Very Secure File Transport Protocol Daemon) is a ...

  8. Notification web 桌面消息推送

    var NotificationHandler = { isNotificationSupported: 'Notification' in window, isPermissionGranted: ...

  9. linux 下的OpenGL的安装配置

    https://blog.csdn.net/qq_38228254/article/details/78521155 本人亲测有效

  10. [macOS] Mojave10.14 夜神安卓模拟器启动问题

    废话不多说,其它的都有在这里讨论: https://bbs.yeshen.com/forum.php?mod=viewthread&tid=8566 我的最终解决办法是,virtualbox安 ...