D. Ghosts
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.
There are nn ghosts in the universe, they move in the OXYOXY plane, each one of them has its own velocity that does not change in time: V→=Vxi→+Vyj→V→=Vxi→+Vyj→ where VxVx is its speed on the xx-axis and VyVy is on the yy-axis.
A ghost ii has experience value EXiEXi, which represent how many ghosts tried to scare him in his past. Two ghosts scare each other if they were in the same cartesian point at a moment of time.
As the ghosts move with constant speed, after some moment of time there will be no further scaring (what a relief!) and the experience of ghost kind GX=∑ni=1EXiGX=∑i=1nEXi will never increase.
Tameem is a red giant, he took a picture of the cartesian plane at a certain moment of time TT, and magically all the ghosts were aligned on a line of the form y=a⋅x+by=a⋅x+b. You have to compute what will be the experience index of the ghost kind GXGX in the indefinite future, this is your task for today.
Note that when Tameem took the picture, GXGX may already be greater than 00, because many ghosts may have scared one another at any moment between [−∞,T][−∞,T].
Input
The first line contains three integers nn, aa and bb (1≤n≤2000001≤n≤200000, 1≤|a|≤1091≤|a|≤109, 0≤|b|≤1090≤|b|≤109) — the number of ghosts in the universe and the parameters of the straight line.
Each of the next nn lines contains three integers xixi, VxiVxi, VyiVyi (−109≤xi≤109−109≤xi≤109, −109≤Vxi,Vyi≤109−109≤Vxi,Vyi≤109), where xixi is the current xx-coordinate of the ii-th ghost (and yi=a⋅xi+byi=a⋅xi+b).
It is guaranteed that no two ghosts share the same initial position, in other words, it is guaranteed that for all (i,j)(i,j) xi≠xjxi≠xj for i≠ji≠j.
Output
Output one line: experience index of the ghost kind GXGX in the indefinite future.
Examples
input
Copy
4 1 1 1 -1 -1 2 1 1 3 1 1 4 -1 -1
output
Copy
8
input
Copy
3 1 0 -1 1 0 0 0 -1 1 -1 -2
output
Copy
6
input
Copy
3 1 0 0 0 0 1 0 0 2 0 0
output
Copy
0
Note
There are four collisions (1,2,T−0.5)(1,2,T−0.5), (1,3,T−1)(1,3,T−1), (2,4,T+1)(2,4,T+1), (3,4,T+0.5)(3,4,T+0.5), where (u,v,t)(u,v,t) means a collision happened between ghosts uu and vv at moment tt. At each collision, each ghost gained one experience point, this means that GX=4⋅2=8GX=4⋅2=8.
In the second test, all points will collide when t=T+1t=T+1.
The red arrow represents the 1-st ghost velocity, orange represents the 2-nd ghost velocity, and blue represents the 3-rd ghost velocity.
x0 + vx0 * t = x1 + vx1 * t;
y0 + vy0 * t = y1 + vy1 * t;
== vy0 - a * vx0 = vy1 - a * vx1
相同的 vy - a * x 数量 - 重复的 x,y 数量
数值过大用map存
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const int mn = 2e5 + 10;
ll x[mn], y[mn];
map<pair<ll, ll>, ll> cnt;
map<ll, ll> tol;
int main()
{
int n;
ll a, b;
scanf("%d %lld %lld", &n, &a, &b);
for (int i = 1; i <= n; i++)
{
ll q;
scanf("%lld %lld %lld", &q, &x[i], &y[i]);
cnt[make_pair(x[i], y[i])]++;
tol[y[i] - a * x[i]]++;
}
ll ans = 0;
for (int i = 1; i <= n; i++)
ans = ans + tol[y[i] - a * x[i]] - cnt[make_pair(x[i], y[i])];
printf("%lld\n", ans);
return 0;
}