Codeforces Round #478 (Div. 2) D - Ghosts

10 篇文章 0 订阅
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+VyjV→=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=ax+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 nnaa and bb (1n2000001≤n≤2000001|a|1091≤|a|≤1090|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 xixiVxiVxiVyiVyi (109xi109−109≤xi≤109109Vxi,Vyi109−109≤Vxi,Vyi≤109), where xixi is the current xx-coordinate of the ii-th ghost (and yi=axi+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) xixjxi≠xj for iji≠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,T0.5)(1,2,T−0.5)(1,3,T1)(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=42=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.

题意:有n个点具有恒定的初速度,设每个点和其他点相遇次数为sumi,求Σsumi(1<=i<=n).

题解:

#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define EPS 10e-6
#define pi acos(-1)
#define N 300000
map<PII, int> mp;
map<ll , int> num;

int main()
{
    int n;
    ll a, b;
    scanf("%d%lld%lld", &n, &a, &b);
    int x, vx, vy;
    ll ans = 0;
    REP(i, n) {
        scanf("%d%d%d", &x, &vx, &vy);
        ans += num[a*vx-vy]-mp[MP(vx, vy)];
        num[a*vx-vy] ++;
        mp[MP(vx, vy)] ++;  //处理同向的点
    }
    printf("%lld\n", ans*2);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值