abc098D Xor Sum 2(two point)
题意
给出一个序列,求出有多少区间满足\(A[l] \oplus A[l+1] \oplus \dots \oplus A[r] = A[l] + A[l + 1] +\dots+ A[r]\)
Sol
一个区间能满足要求一定是所有bit上最多只有一个1
这玩意儿显然有单调性,two point扫一遍
#include<cstdio>
#define LL long long
using namespace std;
const int MAXN = 2e5 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, a[MAXN];
main() {
N = read();
for(int i = 1; i <= N; i++) a[i] = read();
LL l = 1, sxor = 0, sum = 0, ans = 0;
for(int i = 1; i <= N; i++) {
sum += a[i]; sxor ^= a[i];
while(sxor != sum && (l < i))
sum -= a[l], sxor ^= a[l++];
ans += i - l + 1;
}
printf("%lld", ans);
return 0;
}
abc098D Xor Sum 2(two point)的更多相关文章
- HDU 4825 Xor Sum(经典01字典树+贪心)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- 字典树-百度之星-Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...
- HDU 4825 Xor Sum 字典树+位运算
点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
- 2014百度之星第三题Xor Sum(字典树+异或运算)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- Xor Sum 01字典树 hdu4825
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- HDU--4825 Xor Sum (字典树)
题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...
- hdu 4825 Xor Sum trie树
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
随机推荐
- linux+python+robot+jenkins
1.安装python 安装devtoolset # yum groupinstall “Development tools” 安装编译Python需要的包 # yum -y install zlib- ...
- SDUT OJ 图结构练习——最短路径 ( Floyed 算法 AND Dijkstra算法)
图结构练习——最短路径 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- js 原生JS实现轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 训练DCGAN(pytorch官网版本)
将pytorch官网的python代码当下来,然后下载好celeba数据集(百度网盘),在代码旁新建celeba文件夹,将解压后的img_align_celeba文件夹放进去,就可以运行代码了. 输出 ...
- Feel Good(两遍单调栈维护区间+前缀和)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- pyquery的简单操作
一.初始化 1.html初始化 html = ''' <div> <ul> <li class="item-0">first item</ ...
- win7和centos7双系统--转
转自http://blog.chinaunix.net/uid-30867756-id-5758575.html 参考:http://blog.csdn.net/hsg77/article/detai ...
- PostgreSQL精简命令:
dos命令行连接PostgreSQL: . 接入PostgreSQL数据库: psql -h IP地址 -p 端口 -U 用户名 -d 数据库名 . 输入数据库密码 C:\Users\admin\De ...
- (转)Shell——基本运算符
Shell 基本运算符 原文:http://blog.csdn.net/sinat_36053757/article/details/70319481 Shell 和其他编程语言一样,支持多种运算符, ...
- TOJ 2926 Series
Description An arithmetic series consists of a sequence of terms such that each term minus its immed ...