尧图网络科技YAOTU DIGITAL 获取报价
获取报价
首页 / 资讯中心 / 文章详情

B. Valerii Against Everyone

发布时间:2026/9/28 21:16:41

资讯中心
01
ARTICLE

B. Valerii Against Everyone

B. Valerii Against Everyone
time limit per test1 secondmemory limit per test256 megabytesYoure given an array b of length n. Lets define another array a, also of length n, for which ai2bi (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≤r1l2≤r2≤n;al1al11…ar1−1ar1al2al21…ar2−1ar2.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.InputEach 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).OutputFor 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.ExampleInputCopy2 6 4 3 0 1 2 0 2 2 5OutputCopyYES NONoteIn the first case, a[16,8,1,2,4,1]. Choosing l11, r11, l22 and r26 works because 16(81241).In the second case, you can verify that there is no way to select to such subarrays.解题说明此题是一道模拟题找规律能发现如果 b中有两个相等的值那么 aiaj​。取子数组 [i,i]和 [j,j]两个单元素子数组它们不相交且和都等于 aiaj相等。因此只要 bb 中有重复元素答案就是 YES。可以用set集合来判断。#include iostream #includevector #includealgorithm #includeset using namespace std; int main() { int t; cin t; while (t--) { setint s; int n, x; cin n; for (int i 0; i n; i) { cin x; s.insert(x); } if (s.size() n) { cout NO\n; } else { cout YES\n; } } return 0; }
02
RELATED NEWS

相关资讯

更多网站建设与数字化升级内容

03
WHY YAOTU

想打造同款高转化官网?

懂行业、懂生意,从建站到增长一站式陪跑

◈

场景化定制

不做模板站,围绕你的业务场景量身设计,小众不撞款。

◐

营销型架构

以转化目标组织内容与路径,让官网真正带来询盘。

▲

全周期服务

设计、开发、运营、运维一体,上线只是开始。

免费获取你的建站方案

留下需求,专属顾问 24 小时内为你输出方案建议。