第一波转化挺妙的。
令 t l i tl_i tli表示用 − w -w −w的风到原点的时间, t r i tr_i tri表示用 w w w的风到圆点的时间。
显然 ( i , j ) (i,j) (i,j)有解的条件为 ( t l i − t l j ) ( t r i − t r j ) < = 0 (tl_i-tl_j)(tr_i-tr_j)<=0 (tli−tlj)(tri−trj)<=0。
然后就变成了二维偏序问题(据说会卡精度,然后就写分数类了)。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>
#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll
using namespace std;
template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }
typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;
const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=200005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
int f=1,x=0; char c=getchar();
while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
return x*f;
}
int num=0;
struct number { int x,y; } b[MAXN];
bool operator < (number a,number b) { return a.x*b.y<a.y*b.x; }
bool operator == (number a,number b) { return a.x*b.y==a.y*b.x; }
bool operator > (number a,number b) { return a.x*b.y>a.y*b.x; }
pair<number,number> a[MAXN];
int s[MAXN<<2],c[MAXN],n,w;
int query(int x) { int ans=0; for (;x;x-=x&(-x)) ans+=s[x]; return ans; }
void add(int x,int y) { for (;x<=n;x+=x&(-x)) s[x]+=y; }
signed main()
{
n=read(),w=read();
for (int i=1;i<=n;i++)
{
int x=read(),y=read();
if (y>0) a[i].fi=(number){-x,y-w},a[i].se=(number){-x,y+w},b[i]=a[i].se;
else a[i].fi=(number){x,w-y},a[i].se=(number){x,-y-w},b[i]=a[i].se;
}
sort(b+1,b+n+1);
c[0]=1;
for (int i=1;i<=n;i++)
if (b[i]==b[i-1]) c[i]=c[i-1];
else c[i]=c[i-1]+1;
sort(a+1,a+n+1,[&](pair<number,number> x,pair<number,number> y){ return (x.fi<y.fi)||(x.fi==y.fi&&x.se>y.se); });
// for (int i=1;i<=n;i++) cout<<1.0*a[i].fi.x/a[i].fi.y<<" "<<1.0*a[i].se.x/a[i].se.y<<endl;
int ans=0;
for (int i=1;i<=n;i++)
{
int t=c[lower_bound(b+1,b+n+1,a[i].se)-b];
ans+=query(n)-query(t-1);
add(t,1);
}
printf("%lld\n",ans);
return 0;
}