• 如果您觉得本站非常有看点，那么赶紧使用Ctrl+D 收藏吧

CodeForces – 1438E Yurii Can Do Everything(暴力)

1周前 (11-21) 7次浏览

1. l + 1 <= r – 1 ，即区间长度大于等于 3
2. a[ l ] ^ a[ r ] = a[ l + 1 ] + … + a[ r – 1 ]

``````//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
using namespace std;

typedef long long LL;

typedef unsigned long long ull;

const int inf=0x3f3f3f3f;

const int N=2e5+100;

LL a[N];

set<pair<int,int>>st;

int highbit(int x)
{
int cnt=0;
while(x)
{
cnt++;
x>>=1;
}
return cnt+1;
}

int main()
{
#ifndef ONLINE_JUDGE
//  freopen("data.in.txt","r",stdin);
//  freopen("data.out.txt","w",stdout);
#endif
//  ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",a+i);
int ans=0;
for(int l=1;l<=n;l++)
{
int r=l+1;
LL sum=0,limit=(1LL<<highbit(a[l]));
while(r+1<=n&&sum<=limit)
{
sum+=a[r++];
if((a[l]^a[r])==sum)
{
ans++;
st.emplace(l,r);
}
}
}
for(int r=n;r>=1;r--)
{
int l=r-1;
LL sum=0,limit=(1LL<<highbit(a[r]));
while(l-1>=1&&sum<=limit)
{
sum+=a[l--];
if((a[l]^a[r])==sum&&!st.count(make_pair(l,r)))
ans++;
}
}
printf("%dn",ans);

return 0;
}``````