Romantic Glasses
Problem
Iulia has n glasses arranged in a line. The i-th glass has ai units of juice in it. Iulia drinks only from odd-numbered glasses, while her date drinks only from even-numbered glasses.
To impress her date, Iulia wants to find a contiguous subarray of these glasses such that both Iulia and her date will have the same amount of juice in total if only the glasses in this subarray are considered. Please help her to do that.
More formally, find out if there exists two indices l l l, r r r such that 1 ≤ l ≤ r ≤ n 1≤l≤r≤n 1≤l≤r≤n, and a l + a l + 2 + a l + 4 + ⋯ + a r = a l + 1 + a l + 3 + ⋯ + a r − 1 a_l+a_{l+2}+a_{l+4}+⋯+a_r=a_{l+1}+a_{l+3}+⋯+a_{r−1} al+al+2+al+4+⋯+ar=al+1+al+3+⋯+ar−1 if l l l and r r r have the same parity and a l + a l + 2 + a l + 4 + ⋯ + a r − 1 = a l + 1 + a l + 3 + ⋯ + a r a_l+a_{l+2}+a_{l+4}+⋯+a_{r-1}=a_{l+1}+a_{l+3}+⋯+a_r al+al+2+al+4+⋯+ar−1=al+1+al+3+⋯+ar otherwise.
Input
The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 ) (1≤t≤10^4) (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 ) (1≤n≤2⋅10^5) (1≤n≤2⋅105) — the total number of glasses.
The second line of each test case contains n integers a 1 , … , a n a_1,…,a_n a1,…,an ( 1 ≤ a i ≤ 1 0 9 ) (1≤a_i≤10^9) (1≤ai≤109) — the amount of juice in each glass.
The sum of n over all test cases does not exceed 2 ⋅ 1 0 5 2⋅10^5 2⋅105 .
Output
For each test case, output “YES” if there exists a subarray satisfying the condition, and “NO” otherwise.
You can output the answer in any case (for example, the strings “yEs”, “yes”, “Yes” and “YES” will be recognized as a positive answer).
Example
Input
6
3
1 3 2
6
1 1 1 1 1 1
10
1 6 9 8 55 3 14 2 7 2
8
1 2 11 4 1 5 1 2
6
2 6 1 5 7 8
9
2 5 10 4 4 9 6 7 8
Output
YES
YES
NO
YES
NO
YES
Note
In the first test case, Iulia can pick l = 1 l=1 l=1 and r = 3 r=3 r=3. Then she drinks a 1 + a 3 = 1 + 2 = 3 a_1+a_3=1+2=3 a1+a3=1+2=3 units and her date drinks a 2 = 3 a_2=3 a2=3 units of juice.
In the second test case, Iulia can pick l = 2 l=2 l=2 and r = 5 r=5 r=5. Then she drinks a 3 + a 5 = 1 + 1 = 2 a_3+a_5=1+1=2 a3+a5=1+1=2 units and her date drinks a 2 + a 4 = 1 + 1 = 2 a_2+a_4=1+1=2 a2+a4=1+1=2 units of juice.
In the third test case no such contiguous subarray works.
In the fourth test case, Iulia can pick l = 2 l=2 l=2 and r = 8 r=8 r=8. Then she drinks a 3 + a 5 + a 7 = 11 + 1 + 1 = 13 a_3+a_5+a_7=11+1+1=13 a3+a5+a7=11+1+1=13 units and her date drinks a 2 + a 4 + a 6 + a 8 = 2 + 4 + 5 + 2 = 13 a_2+a_4+a_6+a_8=2+4+5+2=13 a2+a4+a6+a8=2+4+5+2=13 units of juice.
Code
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//使用count()判断元素是否在set容器中。若在:返回1,若不在,返回0。
//set容器是用二叉搜索树实现的一种集合,集合中每种元素只出现一次。
//count()是set容器中的一种常用函数。
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
set<ll> a;
a.insert(0);
ll sum=0,op=0;
for(ll i=1;i<=n;i++)
{
ll x;
cin>>x;
//前缀和
if(i&1) sum+=x;//奇加
else sum-=x;//偶减
//其中是否有相等或0
if(a.count(sum)) op=1;
else a.insert(sum);//插入
}
if(op) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}