链接:https://codeforces.com/contest/1166/problem/C

题意:

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 nnintegers 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 yywere equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

思路:

因为需要满足条件 min(|x-y|, |x+y|) <= |x| <= |y| <= max(|x-y|, |x+y|).

所以将x变成-x并不影响条件。所以将所有输入全部取绝对值。

再排序,二分查找。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int MAXN = 2e5+10; int a[MAXN]; int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i], a[i] = abs(a[i]);
sort(a+1, a+1+n);
LL res = 0;
for (int i = 1;i <= n;i++)
res += (upper_bound(a+1, a+1+n, 2*a[i])-a)-i-1;
cout << res << endl; return 0;
}

  

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

  1. Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】

    A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...

  2. Codeforces Round #561 (Div. 2)

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

  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 #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. BZOJ 1207 [HNOI2004]打鼹鼠:dp【类似最长上升子序列】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1207 题意: 有一个n*n的网格,接下来一段时间内会有m只鼹鼠出现. 第i只鼹鼠会在tim ...

  2. vsftpd虚拟用户【公司系统部分享】

    一,安装相关工具包 #yum -y install pam vsftpd db4 db4-utils -- pam 是用来提供身份验证的 -- vsftpd 是ftp服务的主程序 -- db4支持文件 ...

  3. linux应用之jdk环境的安装(centos)

    一.yum安装 1.执行:yum search jdk 已加载插件:fastestmirror, securityLoading mirror speeds from cached hostfile ...

  4. Spring注解实现原理

    ​[Spring如何使用注解机制完成自动装配] Java实例构造时会调用默认父类无参构造方法,Spring正是利用了这一点,让"操作元素的代码"得以执行.   [两种处理策略] ( ...

  5. xml字符串的解析

    import org.jdom.Document;import org.jdom.Element;import org.jdom.JDOMException;import org.jdom.Names ...

  6. MongoDB 分片的原理、搭建、应用 !

    MongoDB 分片的原理.搭建.应用   一.概念: 分片(sharding)是指将数据库拆分,将其分散在不同的机器上的过程.将数据分散到不同的机器上,不需要功能强大的服务器就可以存储更多的数据和处 ...

  7. RT-Thread信号量使用(动态/静态信号量) 及 信号量的四种使用场合

    信号量(Semaphore),有时被称为信号灯,是在多线程环境下使用的一种设施,是可以用来保证两个或多个关键代码段不被并发调用.在进入一个关键代码段之前,线程必须获取一个信号量:一旦该关键代码段完成了 ...

  8. java 基础知识学习 内存泄露(memory leak) VS 内存溢出(out of memory)以及内存管理

    内存泄露(memory leak) VS 内存溢出(out of memory) 内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory ...

  9. ACM实用C语言函数

    函数名: abs 功 能: 求整数的绝对值 用 法: int abs(int i); 程序例: #include <stdio.h> #include <math.h> int ...

  10. netstat -st输出解析(二)

    转自:http://perthcharles.github.io/2015/11/10/wiki-netstat-proc/ netstat -st输出的两个重要信息来源分别是/proc/net/sn ...