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

简介: 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

1. 2
2. 6
3. 4 3 0 1 2 0
4. 2
5. 2 5


output


Copy

1. YES
2. 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;
}


相关文章
大模型应用开发-LangChain入门教程
大模型应用开发-LangChain入门教程
544 0
|
算法 Java 索引
【Java】已解决java.lang.ArrayIndexOutOfBoundsException异常
【Java】已解决java.lang.ArrayIndexOutOfBoundsException异常
1766 0
|
机器学习/深度学习 存储 人工智能
使用 CTransformers 运行 Zephyr-7b、Mistral-7b 模型
使用 CTransformers 运行 Zephyr-7b、Mistral-7b 模型
463 0
|
监控 Devops 持续交付
程序员必须了解的 10个免费 Devops 工具
程序员必须了解的 10个免费 Devops 工具
|
C# 开发工具
【Azure Notification Hub】如何手动删除 Notification Hub 中已注册的设备
【Azure Notification Hub】如何手动删除 Notification Hub 中已注册的设备
125 0
|
存储 传感器 算法
STM32:宏观介绍STM32(内含:1.STM32用途简介+2.系列介绍+3.片上资源/外设+4.命名规则+5.系统结构+6.引脚定义+7.启动配置+8.最小系统电路+9.最小系统实物图)
STM32:宏观介绍STM32(内含:1.STM32用途简介+2.系列介绍+3.片上资源/外设+4.命名规则+5.系统结构+6.引脚定义+7.启动配置+8.最小系统电路+9.最小系统实物图)
978 1
STM32:宏观介绍STM32(内含:1.STM32用途简介+2.系列介绍+3.片上资源/外设+4.命名规则+5.系统结构+6.引脚定义+7.启动配置+8.最小系统电路+9.最小系统实物图)
|
数据挖掘 开发工具 Android开发
开通服务及创建应用|学习笔记
快速学习开通服务及创建应用
开通服务及创建应用|学习笔记
|
Ubuntu Linux Shell
root用户和普通用户
root用户和普通用户
772 0
|
3天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。