题目链接:https://codeforc.es/contest/1438/problem/B
You’re given an array b of length n. Let’s define another array a, also of length n, for which ai=2^bi (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
input
2
6
4 3 0 1 2 0
2
2 5
output
YES
NO
题意
给出 bi, ai = 2 ^ bi ,问是否存在两个不交叉区间,使得两个区间 ai 的和相等。
分析
不要把这题想复杂,只要有两个一样的数就行了。
代码
#include<bits/stdc++.h>
using namespace std;
ll a[10000];
map<ll,ll>mp;
int main(){
int t;
scanf("%d",&t);
while(t--){
mp.clear();
int n;
scanf("%d",&n);
int flag=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
if(mp[a[i]]==0) mp[a[i]]=1;
else flag=1;
}
if(flag==1) printf("Yes\n");
else printf("No\n");
}
return 0;
}