CF 472 div1 D. Contact ATC
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
const int N = 1e5 + 5;
struct fraction {
long long num, deno;
template <typename T>
static inline T gcd(const T a, const T b) {
return (b == 0) ? a : gcd(b, a % b);
}
fraction() {}
inline void simplify() {
if (deno < 0) {
num *= -1;
deno *= -1;
}
long long g = gcd(num < 0 ? -num : num, deno);
num /= g;
deno /= g;
}
fraction(long long _num, long long _deno) : num(_num), deno(_deno) { simplify(); }
inline bool operator<(const fraction& rhs) const { return num * rhs.deno < deno * rhs.num; }
inline bool operator!=(const fraction& rhs) const { return num * rhs.deno != deno * rhs.num; }
};
std::pair<fraction, fraction> T[N];
std::pair<fraction, int> D[N];
int p[N];
int X[N], V[N];
int bitTree[N];
void add(int pos, int num) {
for (int i = ++pos; i < N; i += (i & -i)) {
bitTree[i] += num;
}
}
int sum(int pos) {
int result = 0;
for (int i = ++pos; i; i -= (i & -i)) {
result += bitTree[i];
}
return result;
}
int main() {
int n, w;
while (~scanf("%d %d", &n, &w)) {
for (int i = 0; i < n; ++i) {
scanf("%d %d", &X[i], &V[i]);
}
for (int i = 0; i < n; ++i) {
long long v1 = V[i] - w;
long long v2 = V[i] + w;
T[i] = {fraction(-X[i], v1), fraction(-X[i], v2)};
}
for (int i = 0; i < n; ++i) {
T[i].second.num *= -1;
}
std::sort(T, T + n); //-w increase and w descend
for (int i = 0; i < n; ++i) {
T[i].second.num *= -1;
}
for (int i = 0; i < n; ++i) {
D[i] = {T[i].second, i};
}
std::sort(D, D + n);
for (int i = 0, rk = -1; i < n; ++i) {
if ((i == 0) || D[i].first != D[i - 1].first)
++rk;
p[D[i].second] = rk;
}
long long ans = 0;
for (int i = 0; i < n; ++i) {
ans += sum(N - 1) - sum(p[i] - 1);
add(p[i], 1);
}
printf("%lld\n", ans);
}
return 0;
}
CF 472 div1 D. Contact ATC的更多相关文章
- CF#462 div1 D:A Creative Cutout
CF#462 div1 D:A Creative Cutout 题目大意: 原网址戳我! 题目大意: 在网格上任选一个点作为圆中心,然后以其为圆心画\(m\)个圆. 其中第\(k\)个圆的半径为\(\ ...
- Codeforces 924D Contact ATC (看题解)
Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...
- CF#345 (Div1)
论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...
- CF #356 div1 A. Bear and Prime 100
题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20 ...
- CF #228 div1 B. Fox and Minimal path
题目链接:http://codeforces.com/problemset/problem/388/B 大意是用不超过1000个点构造一张边权为1的无向图,使得点1到点2的最短路的个数为给定值k,其中 ...
- CF #349 div1 B. World Tour
题目链接:http://codeforces.com/problemset/problem/666/B 大意是给一张有向图,选取四个点,使得走这四个点,任意两个点之间走最短路,总距离最长. 3000个 ...
- CF #335 div1 A. Sorting Railway Cars
题目链接:http://codeforces.com/contest/605/problem/A 大意是对一个排列进行排序,每一次操作可以将一个数字从原来位置抽出放到开头或结尾,问最少需要操作多少次可 ...
- CF #345 Div1 D Zip-line
题目链接:http://codeforces.com/contest/650/problem/D 大意是给一个数组,若干询问,每一次把一个数字改为另一个数字,问当前数组最长上升子序列,询问之间是独立的 ...
- CF #299 div1 B. Tavas and Malekas KMP-next数组
题目链接:http://codeforces.com/contest/536/problem/B 一个原始字符串,一个未知字符串,每一次从pos[i]开始覆盖未知字符串,问最后字符串的形式,以及判断过 ...
随机推荐
- 【Python】正则表达式re
re 正则表达式(regular expression)这玩意儿多nb就不用说了,python用re模块来支持正则 首先是一些正则表达式的概念 1. 通配符 . 2. 多字符选择 [...] [abc ...
- APS期刊投稿准备: REVTex格式
APS是American Physics Society的简称.旗下比较有影响力的期刊有: "pra, prb, prc, prd, pre, prl, prstab, prstper, o ...
- 第二周作业(pta存在的问题)
***第一题 错题截图 错因分析:中英文符号用混 改正截图: 思路分析:(1)由输入格式可知,该程序需要用到scanf函数 (2)构建框架 (3)根据要求打入代码 **第二题(正确) 代码截图: 思路 ...
- C第九次博客作业--指针
一.PTA实验作业 题目1:两个4位正整数的后两位互换 1. 本题PTA提交列 2. 设计思路 3.代码截图 本题调试过程碰到问题及PTA提交列表情况说明 刚开始想到的交换是令t=a;a=b;b=t这 ...
- C语言--第二周作业
****学习内容总结**** 1.Git和编辑器截图 2.MOOC截图 3.阅读<提问的智慧>感想 读完<提问的智慧>之后,我认为在提问时,要根据以下步骤: 谨慎明确的描述症状 ...
- 关于collectionView和tableView的两种cell的出列方法的区别
相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...
- [USACO4.1]麦香牛块Beef McNuggets
https://www.luogu.org/problemnew/show/P2737 给出n个数ai,求这n个数不能累加出的最大的数 最大的数无限大或能凑出所有的自然数则输出0 n<=10,a ...
- iOS 11 导航栏 item 偏移问题 和 Swift 下 UIButton 设置 title、image 显示问题
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- intellij idea 找不到或无法加载主类
解决intellij idea 找不到或无法加载主类,请看以下图文介绍 然后idea会重启,等idea启动后 右侧的maven clean 一下,然后再compile就解决了
- c# gridview 新增行
string[] newRow = {"long","d","b"}; Gridview.Rows.Insert(Gridview.Rows ...