[2020.10.26 SSL Simulation Tournament T4] Go to the square [Suffix and]

Insert picture description here
Insert picture description here

analysis:

Let pretreatment odd bits and even bits prefix and suffix and
directly behind the enumeration position + statistics can

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
long long a[N],f[N][3];
int n;
int main(){
    
    
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=2;j++)
			f[i][j]=f[i-1][j]+(i%2==j-1)*a[i];  //预处理
			//等价于f[i][j]=f[i-1][j]+(i%2==j)*a[i],其中j分别为f[i][0]和f[i][1]
			//也就是判断奇偶 顺便累加 不过个人更喜欢1~2存储 所以……
	long long ans=0;
	for(int i=1;i<=n;i++)
		if(f[i-1][2]-f[i-1][1]-(f[n][2]-f[i][2]-f[n][1]+f[i][1])==0) ans++;  //枚举位置
	printf("%lld",ans);
		
	return 0;
}

Guess you like

Origin blog.csdn.net/dgssl_xhy/article/details/109299541