A20 双指针 [ABC098D] Xor Sum 2

视频链接:23 双指针 [ABC098D] Xor Sum 2_哔哩哔哩_bilibili

 

 

Luogu [ABC098D] Xor Sum 2

复制代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
LL a[200005];
LL s1,s2,ans;
//s1:算术和, s2:异或和, ans:方案数

int main(){
  int n; cin>>n;
  for(int i=1; i<=n; i++) cin>>a[i];
  
  for(int i=1,j=0; i<=n; ){  //i<=j
    while(j+1<=n&&s1+a[j+1]==(s2^a[j+1])){ //预判
      j++;
      s1+=a[j];
      s2^=a[j];
    }
    ans+=j-i+1; 
    s1-=a[i];
    s2^=a[i];
    i++;
  }
  cout<<ans<<endl;
  return 0;
}
复制代码

 

posted @   董晓  阅读(437)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示