思路:

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

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. bzoj 4753 [Jsoi2016]最佳团体——0/1分数规划

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4753 0/1分数规划裸题. #include<iostream> #includ ...

  2. Scala学习——类,继承,接口(中)

    基本类的使用:(初) package com.dtspark.scala.basics /** * trait是一个接口 * 接口的第一次继承用extends,多继承时用with * 多继承时,如果这 ...

  3. caffe solver

    caffe solver https://groups.google.com/forum/#!topic/caffe-users/mUIi42aKWHQ https://github.com/BVLC ...

  4. JavaScript高级程序设计学习笔记第六章--面向对象程序设计

    1.ECMAScript没有类的概念,ECMA-262 把对象定义为:“无序属性的集合,其属性可以包含基本值.对象或者函数.”,有点类似于散列表 2.ECMAScript 中有两种属性:数据属性和访问 ...

  5. RHEL6安装JDK7

    一.安装准备 1.操作系统:redhat-server-6.1-x86_64 下载地址: http://www.verycd.com/files/d39b97540497d24175340915244 ...

  6. 《Java多线程编程核心技术》读后感(九)

    当interrupt方法遇到wait方法 当线程呈wait()状态时,调用线程对象的interrupt()会出现InterruptedException异常 package Third; public ...

  7. 2-7 Flutter开发工具使用指南

    这里选择用哪个模拟器运行 Mac系统下可以通过这个Open IOS Siumlator打开IOS模拟器 debug用来调试的 可以创建新的模拟器 选择安卓模拟器的版本 这是sdk的配置 点开就是打开了 ...

  8. 24.集成ASP.NETCore Identity

    正常的情况下view页面的错误的显示应该是这么去判断的 这里我们就不加判断为了,直接用这个div 显示就可以了.当有错误会自动显示在div内 asp.net core Identity加入进来 这里用 ...

  9. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  10. 遍历问题 codevs

    1029 遍历问题 1029 遍历问题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description 我们都很熟悉二叉树的前序.中序. ...