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 ...
随机推荐
- html5 手写的canvas实现
试用支持canvas的浏览器,无JS依赖,运用新的HTML5技术DrawBoard.renderDrawer('myHandWrite',{ penColor:'#FF0000', penWidt ...
- Android SDK中 tools 目录下的工具介绍
Android SDK包含了各种各样的定制工具,简介如下: Android模拟器(Android Emulator )它是在你的计算机上运行的一个虚拟移动设备.你可以使用模拟器来在一个实际的Andro ...
- Android 4.0 的 GridLayout
设计素材代码: 1<?xml version="1.0" encoding="utf-8"?> 2<GridLayout//#http://w ...
- JavaScript(4)
myfuns.js //自定义函数 //输入两个数,再输入一个运算符(+,-,*,/),得到结果->函数 function jiSuan(num1,num2,operator){//特别强调 参 ...
- listen 62
The Hangover I'm never drinking again. And this time I mean it! Anyone who's suffered through a bad ...
- Mac使用记录
---恢复内容开始--- brew list //查看brew安装东东 ls //当前目录下内容 brew --cache //查看brew下载目录 /usr/local/Cellar/ //隐藏文件 ...
- HihoCoder1653 : 公平分队([Offer收割]编程练习赛39)(贪心)
描述 小Hi和小Ho在玩一个战争游戏.游戏中2N个战斗单位,其中第i个单位的战斗力是Ai. 现在小Hi和小Ho要各选N个单位组成队伍,当然他们都希望自己队伍的总战斗力越大越好. 为了使分队更加公平,经 ...
- bzoj 4319: Suffix reconstruction 后缀数组+构造
题目大意 给定后缀数组sa,要求构造出满足sa数组的字符串.或输出无解\(n\leq 5*10^5\) 题解 我们按照字典序来考虑每个后缀 对于\(Suffix(sa[i])\)和\(Suffix(s ...
- 1067 Bash 游戏v2
传送门 1067 Bash游戏 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人 ...
- "The object cannot be deleted because it was not found in the ObjectStateManager."
最近优化EF的性能时遇到一个问题, 当在EF生成的Entityes的构造里加上: this.protocolnodes.MergeOption = MergeOption.NoTracking;thi ...