C. A Tale of Two Lands

题目链接
题目大意: 给你一个数列,让你寻找有多少对不同的数使得|x-y|到|x+y|可以覆盖|x|到|y|
思路: 分类讨论一下可以得到一个结论当|2a| >= |b| 时可以满足条件。用upper_bound可以求解

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define IOS ios::sync_with_stdio(false)
#define pf printf
#define pq priority_queue
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define rep(i, s, e) for(int i = s;i <= e; ++ i)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
const int N = 200010;

int n, a[N];
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1;i <= n; ++ i) {
		scanf("%d", &a[i]);
		if(a[i] < 0) a[i] *= -1;
	}
	sort(a+1, a + 1 + n);
	ll res = 0;
	for(int i = 1;i <= n; ++ i) {
		int c = upper_bound(a+i + 1, a + 1 + n, 2 * a[i]) - a;
		c --;
		res += c - i;
//		cout << c << endl;
	}
	printf("%lld\n", res);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值