Romantic Glasses

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 1lrn, 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++ar1 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++ar1=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) (1t104) — 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) (1n2105) — 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) (1ai109) — 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 2105 .

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;
}
  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 在大学时期的浪漫关系一直是一个备受争议的话题。一些人认为,大学时期是探索爱情和建立长期关系的重要时期,而另一些人则认为,大学应该是专注于学业和职业发展的时期,而不是浪漫关系的场所。以下是基于大学时期的浪漫关系的两篇论文,分别代表两种不同的观点: 论文一:大学时期的浪漫关系是有益的 大学时期是年轻人开始探索爱情和建立长期关系的重要时期。在大学中,学生们可以结识不同背景和兴趣爱好的人,这对于他们的成长和发展是很有益的。在恋爱关系中,他们可以学会如何处理冲突、沟通和相互支持。这些技能不仅有助于他们的人际关系,也有助于他们的职业生涯和未来的婚姻生活。 此外,大学时期的浪漫关系可以增加学生的社交生活,让他们更加融入大学社区。这有助于他们建立支持网络,减轻心理压力,促进身心健康。通过参加情侣活动和社交聚会,学生们可以与同龄人分享彼此的经历和想法,这有助于他们扩展视野,丰富生活经验。 因此,大学时期的浪漫关系对于学生的成长和发展是有益的。当然,学生们需要理性对待自己的感情,不要让浪漫关系干扰自己的学业和职业发展。 论文二:大学时期应该专注于学业而非浪漫关系 大学时期是一个学习和成长的阶段,学生应该将精力集中在学业和职业发展上。浪漫关系虽然可以给学生带来快乐和满足感,但如果让浪漫关系成为主要关注的对象,很容易分散学生的注意力,影响他们的学习成果和职业前途。 此外,大学时期的浪漫关系可能会带来许多心理压力和情感波动。学生们常常会陷入情感纠葛、嫉妒和失落中,这会影响他们的身心健康和学习效率。一些浪漫关系可能还会带来意想不到的后果,比如失去 ### 回答2: 大学期间的浪漫关系是一个常见的话题,值得进行辩论。以下将从积极和消极两个方面进行讨论。 积极方面来看,大学期间的浪漫关系可以成为我们成长的机会之一。首先,与他人建立深入的感情联系可以帮助我们更好地了解自己。通过与伴侣相处,我们可以了解自己的优点和缺点,并通过彼此的支持和鼓励来改进自己。这种互动可以帮助我们形成健康的自尊心和自我认知。 其次,浪漫关系可以提供情感支持和安慰。大学生活充满了各种压力和挑战,与他人建立恋爱关系可以让我们有一个可以倾诉和分享的伙伴。在情感上得到满足的同时,我们还可以携手面对学术上和生活上的困难。这种支持帮助我们增强自信心,并克服困难。 然而,大学期间的浪漫关系也有消极的一面。首先,它可能分散我们的注意力。大学是一个学习和成长的重要时期,但投入过多的时间和精力在浪漫关系上可能导致我们忽略了学业和其他机会。与此同时,如果我们对感情投入过多,可能会忽视个人成长和独立性。 此外,大学期间的浪漫关系也可能导致情感压力和痛苦。青春期和大学时期本身就充满挑战和不确定性,加上浪漫关系中的冲突和失望,可能会给我们带来额外的压力。而且,分手可能会对我们的情感和学业产生消极的影响。 综上所述,大学期间的浪漫关系有积极和消极两个方面。我们应该意识到这种关系对我们的影响,并在追求浪漫关系时保持平衡。通过建立健康的关系,我们可以从中获得情感支持和成长的机会,但也要注意避免过度投入和对学业的负面影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值