Codeforces Round #682 (Div. 2) B. Valerii Against Everyone(思维 二进制)

题目链接: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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值