Codeforces Round 431 (Div. 1)
B
Rooter's Song
Codeforces
1900
原题
← AC →
翻译中…

Wherever the destination is, whoever we meet, let's render this song together.

翻译中…

On a Cartesian coordinate plane lies a rectangular stage of size $*w* × *h*$, represented by a rectangle with corners $(0, 0)$, $(*w*, 0)$, $(*w*, *h*)$ and $(0, *h*)$. It can be seen that no collisions will happen before one enters the stage.

翻译中…

On the sides of the stage stand $*n*$ dancers. The $*i*$-th of them falls into one of the following groups:

翻译中…
  • Vertical: stands at $(*x*_{*i*}, 0)$, moves in positive $*y*$ direction (upwards);
  • Horizontal: stands at $(0, *y*_{*i*})$, moves in positive $*x*$ direction (rightwards).
翻译中…

image

翻译中…

According to choreography, the $*i*$-th dancer should stand still for the first $*t*_{*i*}$ milliseconds, and then start moving in the specified direction at $1$ unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

翻译中…

When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on.

翻译中…

image

翻译中…

Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.

翻译中…

Input

翻译中…

The first line of input contains three space-separated positive integers $*n*$, $*w*$ and $*h*$ ($1 ≤ *n* ≤ 100 000$, $2 ≤ *w*, *h* ≤ 100 000$) — the number of dancers and the width and height of the stage, respectively.

翻译中…

The following $*n*$ lines each describes a dancer: the $*i*$-th among them contains three space-separated integers $*g*_{*i*}$, $*p*_{*i*}$, and $*t*_{*i*}$ ($1 ≤ *g*_{*i*} ≤ 2$, $1 ≤ *p*_{*i*} ≤ 99 999$, $0 ≤ *t*_{*i*} ≤ 100 000$), describing a dancer's group $*g*_{*i*}$ ($*g*_{*i*} = 1$ — vertical, $*g*_{*i*} = 2$ — horizontal), position, and waiting time. If $*g*_{*i*} = 1$ then $*p*_{*i*} = *x*_{*i*}$; otherwise $*p*_{*i*} = *y*_{*i*}$. It's guaranteed that $1 ≤ *x*_{*i*} ≤ *w* - 1$ and $1 ≤ *y*_{*i*} ≤ *h* - 1$. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

翻译中…

Output

翻译中…

Output $*n*$ lines, the $*i*$-th of which contains two space-separated integers $(*x*_{*i*}, *y*_{*i*})$ — the stopping position of the $*i*$-th dancer in the input.

翻译中…

Note

翻译中…

The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure.

翻译中…

image

翻译中…

In the second example, no dancers collide.

翻译中…

样例

Input #1
8 10 8
1 1 10
1 4 13
1 7 1
1 8 2
2 2 0
2 5 14
2 6 0
2 6 1
Output #1
4 8
10 5
8 8
10 6
10 2
1 8
7 8
10 6
InputCopy OutputCopy
Input #2
3 2 3
1 1 2
2 1 1
1 1 5
Output #2
1 3
2 1
1 3
InputCopy OutputCopy
题目信息
题号
848B
时间限制
2 s
内存限制
256 MB
标签
构造
数据结构
计算几何
模拟
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。