#654
Unrated
Walking in Manhattan
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John and his QQ (1Q21051 \leq Q \leq 2 \cdot 10^5) cows are in Manhattan on vacation, but the cows have escaped and are now walking around freely in the city! Manhattan is huge – so huge that its NN (1N21051 \le N \le 2 \cdot 10^5) roads stretch infinitely in the xx-yy plane, but conveniently, those roads all run perfectly horizontally or vertically. Each horizontal and vertical road can be modeled by an equation of the form y=ciy = c_i or x=cix = c_i, where cic_i is an integer in the range 00 to 10910^9 inclusive.

Farmer John knows exactly where each cow started walking and how long ago they escaped. Cows are very predictable, so each of them walks according to the following pattern: They only walk north (+y+y) or east (+x+x) at one unit per second.If they are currently on a single road, they continue walking along the road's direction.If they are at the intersection of two roads, they walk north if they have been walking for an even number of seconds and east otherwise.

Given the layout of Manhattan and the information for each cow, help Farmer John determine where his cows are now!

입력

The first line contains NN and QQ.

The next NN lines describe the roads. Each road is described by a direction (H or V) and a coordinate cic_i. It is guaranteed that the roads are unique.

The next QQ lines describe the cows. Each cow is described by three integers (xi,yi,di)(x_i, y_i, d_i), meaning that they started walking from (xi,yi)(x_i, y_i) exactly did_i seconds ago. It is guaranteed that (xi,yi)(x_i, y_i) lies on some road, and 0xi,yi,di1090 \le x_i, y_i, d_i \le 10^9.

출력

Output QQ lines, where the iith line contains the current position of the iith cow.

예제 입력 1

4 5
V 7
H 4
H 5
V 6
6 3 10
6 4 10
6 5 10
6 6 10
100 4 10

예제 출력 1

14 5
7 13
6 15
6 16
110 4

점수

Inputs 2-4 satisfy N,Q,ci,xi,yi,di100N, Q, c_i, x_i, y_i, d_i \leq 100.Inputs 5-9 satisfy N,Q3000N, Q\le 3000.Inputs 10-20 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.