CF1915E.Romantic Glasses

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Iulia has nn glasses arranged in a line. The ii-th glass has aia_i 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 ll, rr such that 1≤l≤r≤n1 \leq l \leq r \leq n, and al+al+2+al+4+⋯+ar=al+1+al+3+⋯+ar−1a_l + a_{l + 2} + a_{l + 4} + \dots + a_{r} = a_{l + 1} + a_{l + 3} + \dots + a_{r-1} if ll and rr have the same parity and al+al+2+al+4+⋯+ar−1=al+1+al+3+⋯+ara_l + a_{l + 2} + a_{l + 4} + \dots + a_{r - 1} = a_{l + 1} + a_{l + 3} + \dots + a_{r} otherwise.

尤莉娅有 nn 个杯子排成一行。第 ii 个杯子中有 aia_i 单位果汁。尤莉娅只从编号为奇数的杯子中饮用,而她的约会对象只从编号为偶数的杯子中饮用。

为了给约会对象留下深刻印象,尤莉娅希望找出一个连续子数组(即一段连续的杯子),使得仅考虑该子数组中的杯子时,她和约会对象所饮果汁总量相等。请帮她解决这个问题。

更形式化地说:判断是否存在两个下标 ll、rr,满足 1≤l≤r≤n1 \leq l \leq r \leq n,且当 ll 与 rr 同为奇数或同为偶数时,有

al+al+2+al+4+⋯+ar=al+1+al+3+⋯+ar−1,a_l + a_{l + 2} + a_{l + 4} + \dots + a_{r} = a_{l + 1} + a_{l + 3} + \dots + a_{r-1},

否则(即 ll 与 rr 奇偶性不同)有

al+al+2+al+4+⋯+ar−1=al+1+al+3+⋯+ar.a_l + a_{l + 2} + a_{l + 4} + \dots + a_{r - 1} = a_{l + 1} + a_{l + 3} + \dots + a_{r}.

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the total number of glasses.

The second line of each test case contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the amount of juice in each glass.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 玻璃杯的总数。

每个测试用例的第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 每个玻璃杯中果汁的量。

所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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).

对于每个测试用例,如果存在满足条件的子数组,则输出 “YES”,否则输出 “NO”。

您可以以任意大小写形式输出答案(例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    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

    输出#1

    YES
    YES
    NO
    YES
    NO
    YES

说明/提示

In the first test case, Iulia can pick l=1l=1 and r=3r=3. Then she drinks a1+a3=1+2=3a_1+a_3=1+2=3 units and her date drinks a2=3a_2=3 units of juice.

In the second test case, Iulia can pick l=2l=2 and r=5r=5. Then she drinks a3+a5=1+1=2a_3+a_5=1+1=2 units and her date drinks a2+a4=1+1=2a_2+a_4=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=2l=2 and r=8r=8. Then she drinks a3+a5+a7=11+1+1=13a_3+a_5+a_7=11+1+1=13 units and her date drinks a2+a4+a6+a8=2+4+5+2=13a_2+a_4+a_6+a_8=2+4+5+2=13 units of juice.

在第一个测试用例中,Iulia 可以选择 l=1l=1 和 r=3r=3。此时她喝掉 a1+a3=1+2=3a_1+a_3=1+2=3 单位果汁,而她的约会对象喝掉 a2=3a_2=3 单位果汁。

在第二个测试用例中,Iulia 可以选择 l=2l=2 和 r=5r=5。此时她喝掉 a3+a5=1+1=2a_3+a_5=1+1=2 单位果汁,而她的约会对象喝掉 a2+a4=1+1=2a_2+a_4=1+1=2 单位果汁。

在第三个测试用例中,不存在满足条件的连续子数组。

在第四个测试用例中,Iulia 可以选择 l=2l=2 和 r=8r=8。此时她喝掉 a3+a5+a7=11+1+1=13a_3+a_5+a_7=11+1+1=13 单位果汁,而她的约会对象喝掉 a2+a4+a6+a8=2+4+5+2=13a_2+a_4+a_6+a_8=2+4+5+2=13 单位果汁。

输入解题思路,AI测评打分。不知道怎么写?

首页