luogu3760 [TJOI2017]异或和
2024-09-07 23:42:31
看这里
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, s[100005], a[100005], c[2][1000005], ans;
int lb(int x){
return x&-x;
}
void add(int x, int p){
if(p==0) c[x][0]++;
else
for(int i=p; i<=1000000; i+=lb(i))
c[x][i]++;
}
int query(int x, int p){
int re=0;
for(int i=p; i; i-=lb(i))
re += c[x][i];
return re+c[x][0];
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%d", &s[i]);
s[i] += s[i-1];
}
for(int i=0; i<20; i++){
int cnt=0, now=0;
memset(c, 0, sizeof(c));
add(0, 0);
for(int j=1; j<=n; j++){
int tmp=s[j]&(1<<i);
if(tmp) cnt = query(1, 1000000) - query(1, a[j]) + query(0, a[j]);
else cnt = query(0, 1000000) - query(0, a[j]) + query(1, a[j]);
add(tmp>0, a[j]);
if(cnt&1) now ^= 1;
a[j] |= tmp;
}
if(now) ans |= 1<<i;
}
cout<<ans<<endl;
return 0;
}
最新文章
- document.getElementById()与 $()区别
- mac下使用gcc
- 程序猿,千万别说你不了解Docker!
- SqlServer性能优化(一)
- poj3468(线段树 边覆盖)
- JavaEE Tutorials (21) - Java EE安全:高级主题
- Jquery中$.ajax()方法参数详解(转)
- JVM内存配置详解(转)
- Java I/O— 梳理各种“流”
- 探索Windows命令行系列(3):命令行脚本基础
- DES加密And解密
- Linux入门(10)——Ubuntu16.04使用pip3和pip安装numpy,scipy,matplotlib等第三方库
- 文件自动备份和同步bypy和syncthing
- Redis配置解读
- JavaScript Practices
- body标签
- Spring基于纯注解方式的使用
- SpringMVC使用Burlap发布远程服务
- 网络基础之IP地址和子网掩码
- nginx 添加https 配置