资讯详情

B. Valerii Against Everyone

📅 2026/9/28 21:16:48 | 华诺云谱 👁 阅读
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; }
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑