CF1915E.Romantic Glasses
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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, r such that 1≤l≤r≤n, and al+al+2+al+4+⋯+ar=al+1+al+3+⋯+ar−1 if l and r have the same parity and al+al+2+al+4+⋯+ar−1=al+1+al+3+⋯+ar otherwise.
尤莉娅有 n 个杯子排成一行。第 i 个杯子中有 ai 单位果汁。尤莉娅只从编号为奇数的杯子中饮用,而她的约会对象只从编号为偶数的杯子中饮用。
为了给约会对象留下深刻印象,尤莉娅希望找出一个连续子数组(即一段连续的杯子),使得仅考虑该子数组中的杯子时,她和约会对象所饮果汁总量相等。请帮她解决这个问题。
更形式化地说:判断是否存在两个下标 l、r,满足 1≤l≤r≤n,且当 l 与 r 同为奇数或同为偶数时,有
al+al+2+al+4+⋯+ar=al+1+al+3+⋯+ar−1,
否则(即 l 与 r 奇偶性不同)有
al+al+2+al+4+⋯+ar−1=al+1+al+3+⋯+ar.
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the total number of glasses.
The second line of each test case contains n integers a1,…,an (1≤ai≤109) — the amount of juice in each glass.
The sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 玻璃杯的总数。
每个测试用例的第二行包含 n 个整数 a1,…,an(1≤ai≤109)—— 每个玻璃杯中果汁的量。
所有测试用例的 n 之和不超过 2⋅105。
输出格式
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=1 and r=3. Then she drinks a1+a3=1+2=3 units and her date drinks a2=3 units of juice.
In the second test case, Iulia can pick l=2 and r=5. Then she drinks a3+a5=1+1=2 units and her date drinks 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 and r=8. Then she drinks a3+a5+a7=11+1+1=13 units and her date drinks a2+a4+a6+a8=2+4+5+2=13 units of juice.
在第一个测试用例中,Iulia 可以选择 l=1 和 r=3。此时她喝掉 a1+a3=1+2=3 单位果汁,而她的约会对象喝掉 a2=3 单位果汁。
在第二个测试用例中,Iulia 可以选择 l=2 和 r=5。此时她喝掉 a3+a5=1+1=2 单位果汁,而她的约会对象喝掉 a2+a4=1+1=2 单位果汁。
在第三个测试用例中,不存在满足条件的连续子数组。
在第四个测试用例中,Iulia 可以选择 l=2 和 r=8。此时她喝掉 a3+a5+a7=11+1+1=13 单位果汁,而她的约会对象喝掉 a2+a4+a6+a8=2+4+5+2=13 单位果汁。
输入解题思路,AI测评打分。不知道怎么写?