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 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的更多相关文章
- 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 ...
- Codeforces Round #561 (Div. 2)
C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...
- 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 ...
- 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 ...
- Codeforces Round 561(Div 2)题解
这是一场失败的比赛. 前三题应该是随便搞的. D有点想法,一直死磕D,一直WA.(赛后发现少减了个1……) 看E那么多人过了,猜了个结论交了真过了. 感觉这次升的不光彩……还是等GR3掉了洗掉这次把, ...
- Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)
传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- the art of seo(chapter eight)
How Social Media and User Data Play a Role in Search Results and Rankings ***Correlation Between Soc ...
- [原创]Java给word中的table赋值
一.准备工作: 下载PageOffice for Java:http://www.zhuozhengsoft.com/dowm/ 二. 实现方法: 要调用PageOffice操作Word中的tabl ...
- Linux_服务器_03_xxx is not in the sudoers file.This incident will be reported.的解决方法
1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是:chmod u+w /etc/sudoers 3.编辑sudoers文件vi /etc/sud ...
- HttpClient_02_实现https协议
二.参考文档 1.Java 和 HTTP 的那些事(四) HTTPS 和 证书 1. 轻松把玩HttpClient之配置ssl,采用设置信任自签名证书实现https 2.如何使用HttpClient来 ...
- 作业2nd
1. 国内: 雷军作为中国互联网代表人物及环球年度电子商务创新首领人物,曾获中国经济年度人物及十大财智首领人物.中国互联网年度人物等多项国表里荣誉,并当选<福布斯>(亚洲版)2014年度贸 ...
- docker镜像管理基础
[root@node01 ~]# docker pull quay.io/coreos/flannel:v0.10.0-amd64 v0.10.0-amd64: Pulling from coreos ...
- UOJ_407_【IOI2018】狼人
http://uoj.ac/problem/407 分析: 分别建立最小/最大kruskal重构树. 每次询问给出的两个点能走到的部分分别对应两棵树\(dfs\)序的一段区间. 转化成判断矩形中是否有 ...
- MVC之一、预备知识储备
自动属性 隐式类型 对象初始化器与集合初始化器 匿名类 扩展方法 Lambda表达式 (1).自动属性(Auto-Implemented Properties) C#自动属性可以避免原来这样我们手工声 ...
- shell ss命令
ss命令用来显示处于活动状态的套接字信息.ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比net ...
- ASP.NET MVC (Umbraco)中如何设置网站超时自动退出
原文章请参考 https://edgewebware.com/2014/06/automatically-log-out-members-send-login-page-umbraco/ 在网站开发 ...