CF1698C 3SUM Closure

题目描述

我们定义一个数组是 “3SUM-closed” 的,当且仅当对于任意满足 $1\le i

输入格式

第一行包含一个正整数 $T(1\le T\le1000)$,表示数据组数。 接下来每组第一行包含一个正整数 $n(3\le n\le2\times10^5)$,表示数组的长度。 每组第二行表示所给的数组 $a(-10^9\le a_i\le10^9)$。

输出格式

对于每组数据,若所给数组是“3SUM-closed”的,则输出 `YES`(大小写不敏感,下同);若不是,则输出 `NO`。 **【样例解释】** 对于第一组数据,当 $i=1,j=2,k=3$ 时,$a_1+a_2+a_3=0$,且 $a_2=0$,所以这个数组是“3SUM-closed”的。 对于第二组数据,$a_1+a_4+a_5=-1$,而数组中没有 $-1$,所以该数组不是“3SUM-closed”的。 对于第三组数据,对于每一个 $i,j,k$,都有 $a_i+a_j+a_k=0$,且 $0$ 存在于数组中,所以该数组是“3SUM-closed”的。

说明/提示

In the first test case, there is only one triple where $ i=1 $ , $ j=2 $ , $ k=3 $ . In this case, $ a_1 + a_2 + a_3 = 0 $ , which is an element of the array ( $ a_2 = 0 $ ), so the array is 3SUM-closed. In the second test case, $ a_1 + a_4 + a_5 = -1 $ , which is not an element of the array. Therefore, the array is not 3SUM-closed. In the third test case, $ a_i + a_j + a_k = 0 $ for all distinct $ i $ , $ j $ , $ k $ , and $ 0 $ is an element of the array, so the array is 3SUM-closed.