思路:

搞了半天发现和绝对值无关。

http://codeforces.com/blog/entry/67081

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int n;
while (cin >> n)
{
ll ans = ;
for (int i = ; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); }
sort(a, a + n);
for (int i = ; i < n; i++)
{
ans += upper_bound(a + i + , a + n, * a[i]) - a - i - ;
}
cout << ans << endl;
}
return ;
}
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int n;
while (cin >> n)
{
ll ans = ;
for (int i = ; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); }
sort(a, a + n);
int l = , r = ;
while (l < n)
{
while (r < n && a[r] <= * a[l]) r++;
ans += r - l - ;
l++;
}
cout << ans << endl;
}
return ;
}

CF1166C A Tale of Two Lands的更多相关文章

  1. [CF1166C]A Tale of Two Lands题解

    比赛的时候lowerbound用错了 现场WA on test4(好吧我承认我那份代码确实有除了lowerbound以外的问题) 于是只能手动二分 (我好菜啊QAQ 经过一波数学推算,我们发现,设序列 ...

  2. 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 ...

  3. 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 ...

  4. <每日一题> Day7:CodeForces-1166C.A Tale of Two Lands (二分 + 排序)

    原题链接 参考代码: #include <cstdio> #define mid ((l + r) / 2) #include <algorithm> using namesp ...

  5. CodeForces 1166C A Tale of Two Lands

    题目链接:http://codeforces.com/problemset/problem/1166/C 题目大意 给定 n 个数,任选其中两个数 x,y,使得区间 [min(|x - y|, |x ...

  6. Codeforces Round #561 (Div. 2)

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

  7. ural 1343. Fairy Tale

    1343. Fairy Tale Time limit: 1.0 secondMemory limit: 64 MB 12 months to sing and dance in a ring the ...

  8. 简洁美观的Java博客系统Tale开源了,让每一个有故事的人更好的表达想法

    Tale Tale的英文含义为故事,我相信每个坚持写Blog的人都是有故事的:中文你叫它 塌了 也无所谓 . Tale 使用了轻量级mvc框架 Blade 开发,默认主题使用了漂亮的 pinghsu, ...

  9. 如何快速部署国人开源的 Java 博客系统 Tale

    除了闷头专研技术之外,程序员还需要不断地写作进行技术积累,写博客是其中最重要的方式之一.商业博客平台不少,但是更符合程序员背景的方案,是自己开发一个博客平台或者使用开源的博客平台. 开源的博客平台多如 ...

随机推荐

  1. 一个节点rac+单节点dg网络配置(listener.ora与tnsnames.ora)

    环境说明:  实验环境是 一个节点的 rac + 单机dg    (主备全部用asm存储) tnsnames.ora  文件  (oracle用户) node 1 : node1-> pwd / ...

  2. Vijos1221:神秘的配方

    背景 每天中午的下课铃一响,浙江镇海中学的同学们都会冲出学校来附近的小饭馆吃饭,刹那间天昏地暗,飞砂走石,家家餐馆内都是一片黑压压的人 .馄饨店.饺子馆,在学校附近开一家红一家.身为镇海中学信息中心首 ...

  3. [hiho1586]Minimum

    题意:区间内乘积最小值,带修改.解题关键:线段树裸题,考场上以为x y必须不等,还维护了次小值,尼玛嗨尼玛嗨,划水一整场,心态爆炸. 注意坐标需要+1 #include<cstdio> # ...

  4. Robot FrameWork基础学习(二)

    在Robot Framework中,测试套件(Test Suite)主要是存放测试案例,而资源文件(Resource)就是用来存放用户关键字. 内部资源:Resource 外部资源: External ...

  5. HDU - 1546 ZOJ - 2750 Idiomatic Phrases Game 成语接龙SPFA+map

    Idiomatic Phrases Game Tom is playing a game called Idiomatic Phrases Game. An idiom consists of sev ...

  6. Json文件转Excel

    先创建一个web项目,在根目录放置需要转换的json文件,直接读取静态Json文件加载数据进行转换,代码如下: string Json = string.Empty; List<object&g ...

  7. qscoj#19D(单调队列)

    题目链接:http://qscoj.cn/problem/130/ 题意:中文题诶- 思路:直接用单调栈搞一下就好了 代码: #include <bits/stdc++.h> using ...

  8. Hyperledger Fabric 替换couchDB

    fabric中默认数据存储的方式是levelDB,一个key/value存储的单机数据库.除此之外还提供了另外一种存储方式:couchDB.同样也是一个K/V 数据库,对fabric而言,相比于前者, ...

  9. 2017-9-14 NOIP模拟赛

    送分题 (songfen)e Time Limit: 10 00ms y Memory Limit:128MB题目描述LYK 喜欢干一些有挑战的事, 比如说求区间最大子段和. 它知道这个题目有 O(n ...

  10. Python小世界:匿名函数、高阶函数、推导式

    前言 木子本人搞起Python已有多年,一直觉得什么都会,但是有时候实操起来,才觉得很多底层基础的知识都没有彻底的灵活掌握. 另外,网上关于Python基础知识的各种普及已有太多太多. 附上相关大神的 ...