CF1166C.A Tale of Two Lands
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points ∣x∣ and ∣y∣ on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points ∣x−y∣ and ∣x+y∣ and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.
Here ∣z∣ denotes the absolute value of z.
Now, Jose is stuck on a question of his history exam: "What are the values of x and y?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to n integers a1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these n integers such that the legend could be true if x and y were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.
Vectorland 建国传说中提到了两个整数 x 和 y。几个世纪前,数组之王在数轴上点 ∣x∣ 和 ∣y∣ 处放置了两个标记,并征服了这两点之间(含端点)的所有土地,将其命名为 Arrayland。多年以后,向量之王在数轴上点 ∣x−y∣ 和 ∣x+y∣ 处放置了标记,并征服了这两点之间(含端点)的所有土地,将其命名为 Vectorland。他如此操作,使得 Arrayland 的全部领土(含端点)完全包含于 Vectorland 的领土之内。
此处 ∣z∣ 表示 z 的绝对值。
现在,Jose 正被历史考试中的一道题难住了:“x 和 y 的值是多少?” Jose 不知道答案,但他相信自己已将可能的答案缩小至 n 个整数 a1,a2,…,an。现在,他想知道:从这 n 个整数中任取两个不同元素所构成的无序对中,有多少对满足——若令 x 和 y 分别等于该对中的两个值,则上述传说成立。注意,Jose 可能出错,即可能不存在任何一对数能使传说成立。
输入格式
The first line contains a single integer n (2≤n≤2⋅105) — the number of choices.
The second line contains n pairwise distinct integers a1,a2,…,an (−109≤ai≤109) — the choices Jose is considering.
第一行包含一个整数 n(2≤n≤2⋅105)—— 表示选项的数量。
第二行包含 n 个两两不同的整数 a1,a2,…,an(−109≤ai≤109)—— 表示 Jose 正在考虑的选项。
输出格式
Print a single integer number — the number of unordered pairs x,y formed by different numbers from Jose's choices that could make the legend true.
输出一个整数——即由何塞所选的不同数字构成的无序对 {x,y} 的数量,这些无序对可能使传说成立。
输入输出样例
输入#1
3 2 5 -3
输出#1
2
输入#2
2 3 6
输出#2
1
说明/提示
Consider the first sample. For the pair 2,5, the situation looks as follows, with the Arrayland markers at ∣2∣=2 and ∣5∣=5, while the Vectorland markers are located at ∣2−5∣=3 and ∣2+5∣=7:

The legend is not true in this case, because the interval [2,3] is not conquered by Vectorland. For the pair 5,−3 the situation looks as follows, with Arrayland consisting of the interval [3,5] and Vectorland consisting of the interval [2,8]:

As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair 2,−3, for a total of two pairs.
In the second sample, the only pair is 3,6, and the situation looks as follows:

Note that even though Arrayland and Vectorland share 3 as endpoint, we still consider Arrayland to be completely inside of Vectorland.
考虑第一个样例。对于数对 2,5,情形如下所示:Arrayland 的标记位于 ∣2∣=2 和 ∣5∣=5,而 Vectorland 的标记位于 ∣2−5∣=3 和 ∣2+5∣=7:

此时传说不成立,因为区间 [2,3] 并未被 Vectorland 覆盖。对于数对 5,−3,情形如下所示:Arrayland 对应区间 [3,5],Vectorland 对应区间 [2,8]:

由于 Vectorland 完全包含了 Arrayland,因此传说成立。同样可以验证,传说对数对 2,−3 也成立,总计有两个满足条件的数对。
在第二个样例中,唯一的数对是 3,6,情形如下所示:

注意:尽管 Arrayland 和 Vectorland 共享端点 3,我们仍认为 Arrayland 完全包含于 Vectorland 之内。
输入解题思路,AI测评打分。不知道怎么写?