CF975D.Ghosts

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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→\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrightarrow{j} where VxV_{x} is its speed on the xx-axis and VyV_{y} is on the yy-axis.

A ghost ii has experience value EXiEX_i, 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=∑i=1nEXiGX = \sum_{i=1}^{n} EX_i 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 \cdot 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][-\infty, T].

幽灵们和睦安宁地生活着,它们在空间中漫无目的地游荡,唯一的目的就是恐吓任何挡在它们面前的生物。

宇宙中有 nn 只幽灵,它们在 OXYOXY 平面上运动,每只幽灵都具有一个恒定不变的速度:V→=Vxi→+Vyj→\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrightarrow{j},其中 VxV_{x} 表示其在 xx 轴方向上的速度分量,VyV_{y} 表示其在 yy 轴方向上的速度分量。

幽灵 ii 拥有经验数值 EXiEX_i,表示过去曾有多少只幽灵试图恐吓过它。当两只幽灵在某一时刻恰好处于同一笛卡尔坐标点时,它们会互相恐吓。

由于所有幽灵均以恒定速度运动,因此在经过某一时刻之后,将不再发生任何新的恐吓事件(真是令人欣慰!),幽灵种族的总经验值 GX=∑i=1nEXiGX = \sum_{i=1}^{n} EX_i 也将永远不再增长。

塔米姆是一颗红巨星,他在某一特定时刻 TT 拍摄了一张笛卡尔平面的照片,而神奇的是,照片中所有幽灵恰好共线,位于形如 y=a⋅x+by = a \cdot x + b 的直线上。你需要计算幽灵种族的经验指数 GXGX 在无限远的未来将达到的最终值,这便是你今日的任务。

注意:在塔米姆拍摄照片的时刻 TT,GXGX 可能已经大于 00,因为在时间区间 [−∞,T][-\infty, T] 内,许多幽灵可能早已彼此恐吓过了。

输入格式

The first line contains three integers nn, aa and bb (1≤n≤2000001 \leq n \leq 200000, 1≤∣a∣≤1091 \leq |a| \leq 10^9, 0≤∣b∣≤1090 \le |b| \le 10^9) — the number of ghosts in the universe and the parameters of the straight line.

Each of the next nn lines contains three integers xix_i, VxiV_{xi}, VyiV_{yi} (−109≤xi≤109-10^9 \leq x_i \leq 10^9, −109≤Vxi,Vyi≤109-10^9 \leq V_{x i}, V_{y i} \leq 10^9), where xix_i is the current xx-coordinate of the ii-th ghost (and yi=a⋅xi+by_i = a \cdot x_i + 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≠xjx_i \neq x_j for i≠ji \ne j.

第一行包含三个整数 nn、aa 和 bb(1≤n≤2000001 \leq n \leq 200000,1≤∣a∣≤1091 \leq |a| \leq 10^9,0≤∣b∣≤1090 \le |b| \le 10^9)—— 分别表示宇宙中幽灵的数量以及直线的参数。

接下来的 nn 行,每行包含三个整数 xix_i、VxiV_{xi}、VyiV_{yi}(−109≤xi≤109-10^9 \leq x_i \leq 10^9,−109≤Vxi,Vyi≤109-10^9 \leq V_{x i}, V_{y i} \leq 10^9),其中 xix_i 是第 ii 个幽灵当前的 xx 坐标(其 yy 坐标为 yi=a⋅xi+by_i = a \cdot x_i + b)。

保证任意两个幽灵的初始位置均不相同,即对所有 i≠ji \ne j,均有 xi≠xjx_i \neq x_j。

输出格式

Output one line: experience index of the ghost kind GXGX in the indefinite future.

输出一行:幽灵种族 GXGX 在无限远的未来的经验指数。

输入输出样例

  • 输入#1

    4 1 1
    1 -1 -1
    2 1 1
    3 1 1
    4 -1 -1

    输出#1

    8
  • 输入#2

    3 1 0
    -1 1 0
    0 0 -1
    1 -1 -2

    输出#2

    6
  • 输入#3

    3 1 0
    0 0 0
    1 0 0
    2 0 0

    输出#3

    0

说明/提示

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 \cdot 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.

共有四次碰撞:(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),其中(u,v,t)(u,v,t)表示幽灵 uu 与幽灵 vv 在时刻 tt 发生碰撞。每次碰撞中,每个幽灵获得 1 点经验,因此 GX=4⋅2=8GX = 4 \cdot 2 = 8。

在第二个测试用例中,所有点将在 t=T+1t = T + 1 时发生碰撞。

红色箭头表示第 1 只幽灵的速度,橙色箭头表示第 2 只幽灵的速度,蓝色箭头表示第 3 只幽灵的速度。

输入解题思路,AI测评打分。不知道怎么写?

首页