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 ...
随机推荐
- sql update 代替游标写法
update TB_AreaUserDevice_Relation set OrderID = t.r from TB_AreaUserDevice_Relation rel inner join ( ...
- ELK 实用架构
- 003 Android常见错误汇总
1.installation failed with message invalid file 解决办法: <1>.点击工具栏上的Build中的Clean Project <2> ...
- 1011 A+B 和 C (15 分)
#include <iostream> using namespace std; int main(){ int t; cin >> t; double a, b, c; // ...
- 【算法笔记】B1014 福尔摩斯的约会
1014 福尔摩斯的约会 (20 分) 大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hy ...
- Convert DataTable to List<T> where Class of List is Dynamic
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...
- JedisPool
package redis; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis. ...
- (转)关于INF为0x3f3f3f3f
转自https://blog.csdn.net/jiange_zh/article/details/50198097 在算法竞赛中,我们常常需要用到一个“无穷大”的值,对于我来说,大多数时间我会根据具 ...
- 多租户概念以及FreeLink多租户设计思想
多租户实现思想 多租户技术的实现重点,在于不同租户间应用程序环境的隔离(application context isolation)以及数据的隔离(data isolation),以维持不同租户间应用 ...
- rabbitmq 事务消息
事务消息主要用在发送方 在connection上加上事务属性, 发送方感知到本地事务执行失败, 需要通知broker将先前已经接收到的消息rollback,不要发给后面的消费者, 满足强一致性的要求 ...