题目

C - C

CodeForces - 1166C

The legend of the foundation of Vectorland talks of two integers xx and yy. 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 xx and yy?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to nn integers a1,a2,…,ana1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these nn integers such that the legend could be true if xx and yy 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.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105)  — the number of choices.

The second line contains nn pairwise distinct integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the choices Jose is considering.

Output

Print a single integer number — the number of unordered pairs {x,y}{x,y} formed by different numbers from Jose's choices that could make the legend true.

Examples

Input
3
2 5 -3
Output
2
Input
2
3 6
Output
1

Note

Consider the first sample. For the pair {2,5}{2,5}, the situation looks as follows, with the Arrayland markers at |2|=2|2|=2and |5|=5|5|=5, while the Vectorland markers are located at |2−5|=3|2−5|=3 and |2+5|=7|2+5|=7:

The legend is not true in this case, because the interval [2,3][2,3] is not conquered by Vectorland. For the pair {5,−3}{5,−3}the situation looks as follows, with Arrayland consisting of the interval [3,5][3,5] and Vectorland consisting of the interval [2,8][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}{2,−3}, for a total of two pairs.

In the second sample, the only pair is {3,6}{3,6}, and the situation looks as follows:

Note that even though Arrayland and Vectorland share 33 as endpoint, we still consider Arrayland to be completely inside of Vectorland.

题意:给出x轴上的一些坐标,从中任选两个a,b,

要求满足区间【a,b】在【abs(a-b),abs(a+b)】内,输出满足的个数

思路:由于给出的坐标无论正负都与结果无关,所以先把给出的坐标一律转换为正数,将这些数从小到大排序,假设a<b,只要满足a-b<=a ==>即 2*a>=b且a和b之间任意一个坐标都满足要求即可

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int s[t+5];
for(int i=0;i<t;i++)
{
cin>>s[i];
s[i]=abs(s[i]);
}
sort(s,s+t);
int ct=0;
for(int i=0;i<t;i++)
{
int l=0,r=i,st=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(s[mid]*2>=s[i])
{
r=mid-1;
st=mid;
}
else
l=mid+1;
}
if(st!=-1)
{
ct+=(i-st);
}
}
cout<<ct<<endl;
}

2021.3.3--vj补题的更多相关文章

  1. 2021.5.22 vj补题

    A - Marks CodeForces - 152A 题意:给出一个学生人数n,每个学生的m个学科成绩(成绩从1到9)没有空格排列给出.在每科中都有成绩最好的人或者并列,求出最好成绩的人数 思路:求 ...

  2. QFNU-ACM 2021.10.09 Rating补题

    A - A CodeForces - 478A 注意点: 和为0时要特判一下. 代码: #include<bits/stdc++.h> using namespace std; int m ...

  3. 2021-5-15 vj补题

    C - Win or Freeze CodeForces - 151C 题目内容: You can't possibly imagine how cold our friends are this w ...

  4. hdu5017:补题系列之西安网络赛1011

    补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...

  5. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  6. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  7. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  8. [数]补题ver.

    上次补题好像把两次训练混在一起了,总之先按时间顺序补完这一次|ू・ω・` ) HDU-6301 不会的东西不能逃避.jpg 红小豆非常讨厌构造题,因为非常不会,并且非常逃避学习这类题,因为总也搞不清楚 ...

  9. 4.30-5.1cf补题

    //yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...

  10. ICPC南京补题

    由于缺的题目比较多,竟然高达3题,所以再写一篇补题的博客 Lpl and Energy-saving Lamps During tea-drinking, princess, amongst othe ...

随机推荐

  1. x和y为正整数变量,求满足 x+y | xy 的通解。

    x和y为正整数变量,求满足 x+y | xy 的通解. 解:由题设可知存在正整数t满足t(x+y)=xy. 设m=(x,y),则存在正整数u和v满足: x=mu, y=mv, (u,v)=1. 于是有 ...

  2. Python面向对象编程及内置方法

    在程序开发中,要设计一个类,通常需要满足以下三个要求: [1]类名 这类事物的名字,满足大驼峰命名法 [2]属性 这类事物具有什么样的特征 [3]方法 这类事物具有什么样的行为 定义简单的类: 定义只 ...

  3. gimp 缩放图片 python script

    滤镜 -> Python Fu -> 控制台,复制粘贴下面代码. 然后 scale_image(800, 800) 图片自动缩放为 800*800 了 这个代码是傻傻的缩放,你可以把它改成 ...

  4. freeswitch的event事件处理

    概述 之前的文章中,我们讲解了freeswitch的源码基本结构,如何新增一个插件式模块,以及如何在模块中新增一个命令式API接口和APP接口. freeswitch本身是事件驱动的,它可以并发响应多 ...

  5. 图神经网络-环境配置与PyG库

    环境配置与PyG中图与图数据集的表示和使用 一.引言 PyTorch Geometric (PyG)是面向几何深度学习的PyTorch的扩展库,几何深度学习指的是应用于图和其他不规则.非结构化数据的深 ...

  6. shp的基本操作

    本节将介绍如何利用python完成对shp的基本操作 1.读取shp四至 import shapefile sf = shapefile.Reader(r"E:\shp\1.shp" ...

  7. scrum项目冲刺_day03总结

    摘要:今日完成任务. 1.图像识别已完成,但是较为卡顿,仍需优化 2.语音输入正在进行 3.搜索功能正在进行 总任务: 一.appUI页面(已完成) 二.首页功能: 1.图像识别功能(基本完成) 2. ...

  8. 开源的物联网技术平台(Thingsboard)

    1   总体说明 1.1   产品概述 1.1.1 Thingsboard作用 1.置备并控制设备. 2.采集设备数据并进行数据可视化. 3.分析设备数据,触发告警. 4.将数据传输到另一个系统. 5 ...

  9. symfony2 数据库原生查询

    1. 数组,没有键名 但只查询出第一个结果 $conn = $this->getDoctrine()->getConnection(); $data = $conn->fetchAr ...

  10. Linux系列(42) - 防火墙相关命令

    # 开启 service firewalld start # 重启 service firewalld restart # 关闭 service firewalld stop # 查看防火墙规则 fi ...