Yurii Can Do Everything
题意:求 l,r的对数使得
思路:直接暴力,因为ai ^ aj 不会进位 所以从左边枚举当sum>2*ai时退出 再从右边枚举一边,放入set去重
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=2e18+100;
const int maxn=2e5+100;
int pre[maxn],a[maxn];
signed main()
{
set<pii>s;
int n;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
pre[i]=pre[i-1]+a[i];
}
for(int i=1; i<=n; i++)
{
for(int j=i+2; j<=n; j++)
{
if((a[i]^a[j])==pre[j-1]-pre[i])
{
s.insert({i,j});
}
if(pre[j-1]-pre[i]>2*a[i])break;
}
}
for(int j=n; j>=1; j--)
{
for(int i=j-2; i>=1; i--)
{
if((a[i]^a[j])==pre[j-1]-pre[i])
{
s.insert({i,j});
}
if(pre[j-1]-pre[i]>2*a[j])break;
}
}
cout<<s.size()<<"\n";
}