关于求数组中两部分是否相等问题可以考虑前缀和的思路

当之后你不记得标题由何而来时,请回顾codeforces round 918(div4)的E题

/*这道题的核心就是题干中等式的转化,然后利用前缀和。还要注意flag[0] = 1不能漏,不然就都是yes了*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int maxn = 2e5;
const int mod = 1e6 + 7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		ll n, a[maxn], sum = 0;
		int f = 0;
		map<ll, ll>flag;
		flag[0] = 1;
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for (int i = 0; i < n; i++)
		{
			if (i % 2 == 0)
			{
				a[i] = -a[i];
			}
			sum += a[i];
			if (flag[sum])
			{
				f = 1;
				break;
			}
			flag[sum]++;
		}
		if (f)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值