#P11078. 「FSLOI Round I」迷雾

    ID: 10276 远端评测题 500ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>线段树洛谷原创O2优化差分洛谷月赛

「FSLOI Round I」迷雾

Description

The Misty Forest can be represented as a grid of size n×mn \times m, where cells with character X have dense fog, while cells with character . are empty.

Denote the cell in the ii-th row from the top and the jj-th column from the left as (i,j)(i,j).

A fog constant kk is given.

FL_sleake made qq moves. The ii-th move consists of one character cic_i and two integers aia_i and bib_i. Specifically:

  • If cic_i is U, take aia_i steps upwards.
  • If cic_i is D, take aia_i steps downwards.
  • If cic_i is L, take aia_i steps to the left.
  • If cic_i is R, take aia_i steps to the right.

In each step, he will go by exactly one cell towards the given direction. However, if he will move outside of the forest after the step, he just stays in the current cell instead.

If FL_sleake stays in a cell with fog after he performs the ii-th move, he will perform an operation on ci+k,ci+2×k,,ci+bi×kc_{i+k},c_{i+2\times k},\dots, c_{i+b_i\times k}. If bi=0b_i=0, No operations will be performed.

An operation on a character cc is replacing it with another character representing the opposite direction of cc. That is:

  • If cc is U, replace it with D.
  • If cc is D, replace it with U.
  • If cc is L, replace it with R.
  • If cc is R, replace it with L.

Initially FL_sleake is at (1,1)(1,1), please find his position after the qq moves.

Recall that kk is the same for all moves.

Input Format

The first line of the input contains four integers n,m,q,kn,m,q,k.

In the following nn lines, each line contains a string of length mm, representing the Misty Forest.

In the following qq lines, the ii-th line contains one character cic_i, and two integers aia_i and bib_i, representing the ii-th move.

Output Format

Output a single line containing two integers xx and yy, representing that FL_sleake's position after the qq moves is (x,y)(x,y).

3 3 4 1
..X
.XX
XXX
D 1 2
R 1 2
D 2 0
L 1 0

1 3

10 10 8 2
XX.XX.X...
XXX..XXX.X
XXX.X.XXXX
XXXXXXX.X.
.XX...XX.X
.XXX.X.X.X
...XXX.XXX
XX...XX...
X..XX....X
XXXXX...XX
U 2 1
L 1 3
R 3 1
L 1 2
D 2 1
R 5 1
L 4 0
D 3 0

1 10

Hint

Example Explanation

In the first example, FL_sleake's position at the beginning and after each move is as follow:

$(1,1) \rightarrow (2,1) \rightarrow (2,2)\rightarrow (1,2) \rightarrow (1,3)$

The sequence c1,c2,,cqc_1,c_2,\dots,c_q at the beginning and after each move is as follow:

$\lbrace \texttt{D,R,D,L} \rbrace \rightarrow \lbrace \texttt{D,R,D,L} \rbrace \rightarrow \lbrace \texttt{D,R,U,R} \rbrace \rightarrow \lbrace \texttt{D,R,U,R} \rbrace \rightarrow \lbrace \texttt{D,R,U,R} \rbrace$

Constraints

Subtasks are used in this problem.

For all tests, it is guaranteed that:

  • 1n,m5001 \leq n,m \leq 500
  • 1k201 \leq k \leq 20
  • 1q2×1051\leq q \leq 2 \times 10^5
  • 1ai,bi1061 \leq a_i,b_i \leq 10^6
  • ci{L,R,U,D}c_i \in \{\texttt{L,R,U,D}\}
Subtask Id Score Special Property
11 55 q=1q=1
22 1515 n,m,q100n,m,q\leq 100
33 2020 k=1k=1
44 3030 n=1n=1
55 -