A Tale of Two Lands

题目链接(点击)

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||x| and |y||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||x−y| and |x+y||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||z| denotes the absolute value of zz.

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|=2 and |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)]内  输出能够组成的个数

思路:

(1)无论点的坐标值是正或负与结果都无关 所以把所有数转换成正数存进去

(2)把所有坐标值排序

(3)假设两个坐标值a<b  若满足2*a>=b 那么就符合题意要求 并且a和b之间的任意一个坐标值与b组合都符合要求

注意:

将坐标值变成绝对值后 可能出现坐标值相等的情况 但也要把它们看成两种情况 因为输入的时候是一正一负 所以两次都要算

AC代码:

二分模板题,但写二分的时候没注意用ans标记前一个mid值 导致错误

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MAX=2e5;
int a[MAX+5],n;
LL sum;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
a[i]=abs(a[i]);
}
sort(a,a+n);
for(int i=0;i<n;i++){
int l=0,r=i,ans=-1;
while(l<=r){
int mid=(l+r)/2;
if(a[mid]*2>=a[i]){
r=mid-1;
ans=mid;
}
else{
l=mid+1;
}
}
if(ans!=-1){
sum+=(i-ans);
}
}
printf("%lld\n",sum);
return 0;
}

Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】的更多相关文章

  1. Codeforces Round #561 (Div. 2)

    C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...

  2. Codeforces Round #561 (Div. 2) C. A Tale of Two Lands

    链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...

  3. Codeforces Round #561 (Div. 2) B. All the Vowels Please

    链接:https://codeforces.com/contest/1166/problem/B 题意: Tom loves vowels, and he likes long words with ...

  4. Codeforces Round #561 (Div. 2) A. Silent Classroom

    链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...

  5. Codeforces Round 561(Div 2)题解

    这是一场失败的比赛. 前三题应该是随便搞的. D有点想法,一直死磕D,一直WA.(赛后发现少减了个1……) 看E那么多人过了,猜了个结论交了真过了. 感觉这次升的不光彩……还是等GR3掉了洗掉这次把, ...

  6. Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)

    传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...

  7. Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)

    A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  8. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  9. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

随机推荐

  1. 二、工具类ImageUtil——图片处理

    这个工具类完成的工作如下: 1.第一个static方法,完成图片格式的转换.统一转换成.jpg格式. package util; import java.awt.Toolkit; import jav ...

  2. Htop/Glances/Dstat性能测试系统监控工具领域的瑞士军刀

    原文链接:https://mp.weixin.qq.com/s/TvfzIy4uXHPOFQ1h5Q4KWg 建议点击原文链接查看 续上篇分享的[性能测试工具],今天整理了常用的系统监控工具,当然有特 ...

  3. Linux 下批量杀死进程

    ps aux|grep python|grep -v grep|cut -c 9-15|xargs kill -15 管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入.下面 ...

  4. VMware Workstation如何修改弹出释放快捷键

    VMware Workstation默认使用Ctrl+Alt键就可以将鼠标从虚拟机脱离出来. 但有时这2个键可能会和其他软件的快捷键冲突,这时候如何设置快捷键呢: 打开WMware Workstati ...

  5. (一) Vue在创建的时候 入口文件 及相关的路由配置(及子路由配置)

    1. 首先明确一点  在书写之前尽量保持相关的文件知道含义 比如 components 啥的 知道是要放什么东西 在这里介绍一下   由于 vue 不是系统学习 所以很多的创建方式可能不一样  就是有 ...

  6. LNMP PHP升级脚本

    升级PHP前,请确认你的网站程序是否支持升级到的PHP版本,防止升级到网站程序不兼容的PHP版本,具体可以去你使用的PHP程序的官网查询相关版本支持信息.v1.3及以后版本大部分情况下也可以进行降级操 ...

  7. 关于mantisBT2.22安装插件Inline column configuration 2.0.0时提示缺少依赖jQuery UI Library 1.8

    1.首先直接下载最新的那个1.12即可 https://github.com/mantisbt-plugins/jQuery-UI/releases 2.上传到mantis的插件目录下:……manti ...

  8. 实现.Net程序中OpenTracing采样和上报配置的自动更新

    前言 OpenTracing是一个链路跟踪的开放协议,已经有开源的.net实现:opentracing-csharp,同时支持.net framework和.net core,Github地址:htt ...

  9. MVC案例之通过配置切换底层存储源(面向接口)

    1.深入理解面向接口编程: 在类中调用接口的方法,而不必关心具体的实现.这将有利于代码的解耦.使程序有更好的可移植性 和可扩展性 动态修改 Customer 的存储方式:通过修改类路径下的 switc ...

  10. Python编程基本规范

    1.命名规范 类:类的名称一般为名词,且以驼峰形式(即每个单词首字母要大写,其余字母小写,单词之间无间隔符号)给出. 函数:一般以动词开头,函数名称要准确.简要地概括本函数的作用.函数名一律小写,如有 ...