CF1438B Valerii Against Everyone(考察数学分析问题)

  

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 cc 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≤10^9 ).

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

Copy

2
6
4 3 0 1 2 0
2
2 5

output

Copy

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.

这道题 分两种情况:

  1.  bi​中有两个数一样
  2.  bi​中的数两两不同

首先对于第一种情况,不妨设 bj​=bk​,其中j<k ,则有解为

 l1​=r1​=j,l2​=r2​=k

输出YES 

对于第二种情况,显然此时在二进制下无论选择任何 bi​进行和运算,都不会有进位,所以若要满足条件,必定存在 bx​=by​,与条件矛盾。此时应输出NONO

因此思路是:判断是否有重复元素。具体实现看代码。

#include <iostream>
#include <algorithm>
using namespace std;
int a[20000];
int n,t;
int main()
{
   cin>>t;
   while(t--)
   {
   	cin>>n;
   	bool flag=0;
   	for(int i=1;i<=n;i++)
	    cin>>a[i];
   	sort(a+1,a+1+n);
   	for(int i=2;i<=n;i++) 
   	
   	if(a[i]==a[i-1])
   	{
   		flag=1;
   		break;
   	}	
	   if(!flag) 
	   cout<<"NO"<<endl;
	   else
	    cout<<"YES"<<endl;
   	
   }
  
   return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法编程张老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值