Logo
(追記) (追記ここまで)

31552번 - Walking in Manhattan 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB111352834.568%

문제

Farmer John and his $Q$ (1ドル \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 $N$ (1ドル \le N \le 2 \cdot 10^5$) roads stretch infinitely in the $x$-$y$ 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 = c_i$ or $x = c_i,ドル where $c_i$ is an integer in the range 0ドル$ to 10ドル^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$) or east ($+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 $N$ and $Q$.

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

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

출력

Output $Q$ lines, where the $i$th line contains the current position of the $i$th 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

The first two cows took the following paths:

(6, 3) -> (6, 4) -> (7, 4) -> (7, 5) -> (8, 5) -> ... -> (14, 5)
(6, 4) -> (6, 5) -> (7, 5) -> (7, 6) -> ... -> (7, 13)

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 January Contest > Gold 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /