#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的更多相关文章

  1. CF#462 div1 D:A Creative Cutout

    CF#462 div1 D:A Creative Cutout 题目大意: 原网址戳我! 题目大意: 在网格上任选一个点作为圆中心,然后以其为圆心画\(m\)个圆. 其中第\(k\)个圆的半径为\(\ ...

  2. Codeforces 924D Contact ATC (看题解)

    Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...

  3. CF#345 (Div1)

    论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...

  4. CF #356 div1 A. Bear and Prime 100

    题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20 ...

  5. CF #228 div1 B. Fox and Minimal path

    题目链接:http://codeforces.com/problemset/problem/388/B 大意是用不超过1000个点构造一张边权为1的无向图,使得点1到点2的最短路的个数为给定值k,其中 ...

  6. CF #349 div1 B. World Tour

    题目链接:http://codeforces.com/problemset/problem/666/B 大意是给一张有向图,选取四个点,使得走这四个点,任意两个点之间走最短路,总距离最长. 3000个 ...

  7. CF #335 div1 A. Sorting Railway Cars

    题目链接:http://codeforces.com/contest/605/problem/A 大意是对一个排列进行排序,每一次操作可以将一个数字从原来位置抽出放到开头或结尾,问最少需要操作多少次可 ...

  8. CF #345 Div1 D Zip-line

    题目链接:http://codeforces.com/contest/650/problem/D 大意是给一个数组,若干询问,每一次把一个数字改为另一个数字,问当前数组最长上升子序列,询问之间是独立的 ...

  9. CF #299 div1 B. Tavas and Malekas KMP-next数组

    题目链接:http://codeforces.com/contest/536/problem/B 一个原始字符串,一个未知字符串,每一次从pos[i]开始覆盖未知字符串,问最后字符串的形式,以及判断过 ...

随机推荐

  1. 【数据结构】 字符串&KMP子串匹配算法

    字符串 作为人机交互的途径,程序或多或少地肯定要需要处理文字信息.如何在计算机中抽象人类语言的信息就成为一个问题.字符串便是这个问题的答案.虽然从形式上来说,字符串可以算是线性表的一种,其数据储存区存 ...

  2. #Python3.6.2(32位) pip安装 和 pygame 环境配置

    #首先确认电脑已经安装python ,可通过在命令行下 执行 python --version确认. 1. 到 https://pypi.python.org/pypi/setuptools/ 下载 ...

  3. RESTful WebService 入门实例

      /* 新建MavenProject,使用以下代码,创建类和POM文件.使用命令行切换到Project根目录,运行mvn package(或者,选中pom.xml 文件右键单击 > run a ...

  4. Matlab绘图基础——图形修饰处理(入门)

    引入--标题.色条.坐标轴.图例等 例一: set(groot,'defaultAxesLineStyleOrder','remove','defaultAxesColorOrder','remove ...

  5. System V IPC 之共享内存

    IPC 是进程间通信(Interprocess Communication)的缩写,通常指允许用户态进程执行系列操作的一组机制: 通过信号量与其他进程进行同步 向其他进程发送消息或者从其他进程接收消息 ...

  6. 转载:解决微信OAuth2.0网页授权回调域名只能设置一个的问题

    项目地址:https://github.com/HADB/GetWeixinCode 说明:微信项目很多,但是回调域名有限,经常使用,做个笔记. 解决微信OAuth2.0网页授权只能设置一个回调域名的 ...

  7. ssm中iReport报表使用json数据源过程体会

    前言:做这个一定要有耐心,因为报表本就是数据杂糅到规整的过程,这篇心得会细讲每一步操作,如果只想着一眼到位,建议close tab 在公司中遇到项目,大概是一个这样的需求,有一个列表和一个标题,需要把 ...

  8. SpringMVC DispatcherServlet 启动和加载过程(源码调试)

    在阅读本文前,最好先阅读以下内容(当然,如果对 Servlet 已经有所了解,则可跳过): http://www.cnblogs.com/cyhbyw/p/8682078.html http://ww ...

  9. Ubuntu安装MariaDB教程

    一.环境 服务器:Ubuntu 16.04.1 LTS(GUN/Linux 4.4.0-91-generic x86_64) 数据库版本:MariaDB 10.3 二.安装流程 2.1 进入Maria ...

  10. node.js基础

    //安装淘宝npm镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org//require表示引包,引包就是引用自己的一个特 ...