You’re given an array b of length n. Let’s define another array a, also of length n, for which ai=2bi (1≤i≤n).
Valerii says that every two non-intersecting subarrays of a have different sums of elements. You want to determine if he is wrong. More formally, you need to determine if there exist four integers l1,r1,l2,r2 that satisfy the following conditions:
1≤l1≤r1<l2≤r2≤n;
al1+al1+1+…+ar1−1+ar1=al2+al2+1+…+ar2−1+ar2.
If such four integers exist, you will prove Valerii wrong. Do they exist?
An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). Description of the test cases follows.
The first line of every test case contains a single integer n (2≤n≤1000).
The second line of every test case contains n integers b1,b2,…,bn (0≤bi≤109).
Output
For every test case, if there exist two non-intersecting subarrays in a that have the same sum, output YES on a separate line. Otherwise, output NO on a separate line.
Also, note that each letter can be in any case.
Example
inputCopy
2
6
4 3 0 1 2 0
2
2 5
outputCopy
YES
NO
Note
In the first case, a=[16,8,1,2,4,1]. Choosing l1=1, r1=1, l2=2 and r2=6 works because 16=(8+1+2+4+1).
In the second case, you can verify that there is no way to select to such subarrays.
题意
给你一个长度为 n n n 的数组 b b b,按 a i = 2 b i a_i=2^{b_i} ai=2bi 形式表示成数组 a a a,问能否在数组 a a a 中找到两个区间使得这两个区间和相等。
思路
情况1: a a a 数组中含有相等的数,那么我就可以选择这两个数作为两个区间。
情况2: a a a 数组中的数各不等,由于 a i a_i ai 的二进制表示中只有 b i b_i bi 位是 1 1 1 其他位全是 0 0 0,那么 b i b_i bi 不同就意味着 a i a_i ai 每个数的和都不存在进位,也就不存在区间相等情况。
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
int main()
{
int t; cin >> t;
while (t--)
{
int n; cin >> n;
unordered_map<int, bool> h;
bool flag = false;
for (int i = 0; i < n; i++)
{
int x; cin >> x;
if (h[x]) flag = true;
else h[x] = true;
}
if (flag) puts("YES");
else puts("NO");
}
return 0;
}