#P10201. [湖北省选模拟 2024] 永恒 / eternity

[湖北省选模拟 2024] 永恒 / eternity

Background

There are always living beings on the ground who dare to face the might of thunderhead-on.

Problem Description

The map of Inazuma can be divided into a grid with NN rows and MM columns. The area in row ii and column jj is denoted as (i,j)(i,j). In the past, in every area there was a Vision holder, whose elemental power number was ci,jc_{i,j} (0ci,j90 \le c_{i,j} \le 9).

The Raiden Shogun brought down the might of thunder and confiscated some Visions. Areas where the Vision has been confiscated are called Thunder Blocked Areas, and the other areas are called Non-Thunder Blocked Areas. Since you opposed the Vision Hunt Decree and are now wanted, you cannot enter Thunder Blocked Areas, and you also cannot leave the Inazuma map.

You are gathering strength, and you can move freely between adjacent Non-Thunder Blocked Areas. Suppose you are currently at (i,j)(i,j), you may move to any one of the four areas (i+1,j),(i1,j),(i,j+1),(i,j1)(i+1,j),(i-1,j),(i,j+1),(i,j-1) that is a Non-Thunder Blocked Area. During one movement, the strength you accumulate is defined as follows: concatenate, in order, the elemental power numbers of the Visions in all areas you pass through, and take the result modulo 1 145 1411\ 145\ 141. For example, if the elemental power numbers of the areas you pass through in order are 3,1,0,3,3,3,2,13,1,0,3,3,3,2,1, then the strength you accumulate is 31033321mod1145141=11451431033321 \bmod 1145141 = 114514. Note that one movement may pass through the same Non-Thunder Blocked Area multiple times. Repeatedly passing through the same Non-Thunder Blocked Area will accumulate strength repeatedly.

The path is vast, Narukami is eternal. The wish for eternity will eventually become an empty dream, and the trend of change cannot be stopped. Inazuma will change over time. During seconds 1Q1 \sim Q, one event happens each second. There are two types of events:

  • 1 x y c: If cc is #, it means the Vision at (x,y)(x,y) has been confiscated, and (x,y)(x,y) becomes a Thunder Blocked Area. If cc is a digit character, it means the Vision holder at (x,y)(x,y) regains a Vision whose elemental power number is cc, or its elemental power number changes to cc, and (x,y)(x,y) becomes a Non-Thunder Blocked Area.

  • 2 sx sy tx ty v: Determine whether there exists a movement that starts from (sx,sy)(sx,sy) and reaches (tx,ty)(tx,ty) such that the strength you accumulate is exactly vv. It is guaranteed that both (sx,sy)(sx,sy) and (tx,ty)(tx,ty) are Non-Thunder Blocked Areas.

Answer all type 2 events. It is guaranteed that there is at least one type 2 event.

Input Format

The input contains N+Q+1N+Q+1 lines.

The first line contains four integers N,M,Q,idN,M,Q,id, where idid denotes the test point number.

The next NN lines each contain MM characters describing the Inazuma map. If the jj-th character in the ii-th line is #, then (i,j)(i,j) is a Thunder Blocked Area. If it is a digit character, then (i,j)(i,j) is a Non-Thunder Blocked Area, and this digit character gives the elemental power number of the Vision held at (i,j)(i,j).

The next QQ lines describe the events that happen each second in chronological order, with the format as described above.

Output Format

Output several lines. For each type 2 event, output one line:

  • If there exists a movement whose accumulated strength is vv, output Yes.
  • Otherwise, output No.
5 5 5 0
19999
14519
99949
9999#
999#0
2 1 1 3 4 114514
2 5 1 3 1 99999
2 1 1 5 5 0
2 5 1 1 5 557047
2 3 1 4 4 838871
Yes
Yes
No
Yes
Yes
见选手目录下的 eternity/eternity2.in 与 eternity/eternity2.ans。
该样例符合测试点 9 ∼ 11 的限制。
见选手目录下的 eternity/eternity3.in 与 eternity/eternity3.ans。

Hint

Sample Explanation 1

Note that in all sample inputs, idid is 00.

For the first query: (1,1)(2,1)(2,2)(2,3)(2,4)(3,4)(1,1)\to (2,1)\to (2,2)\to (2,3)\to (2,4)\to (3,4).

For the second query: (5,1)(5,2)(4,2)(3,2)(3,1)(5,1)\to (5,2)\to (4,2)\to (3,2)\to (3,1).

For the third query, it is blocked by a Thunder Blocked Area, so it is clearly impossible to reach.

For the fourth query: $(5,1)\to (4,1)\to (3,1)\to (2,1)\to (1,1)\to (1,2)\to (1,3)\to (1,4)\to (1,5)$, and the value is 999119999mod1145141=557047999119999 \bmod 1145141=557047.

For the fifth query: $(3,1)\to (4,1)\to (4,2)\to (4,3)\to (4,4)\to (4,3)\to (4,4)$, and the value is 9999999mod1145141=8388719999999\bmod 1145141=838871.

Subtasks

For all testdata, it is guaranteed that 1n,m5001 \le n,m \le 500, 1Q2×1051 \le Q \le 2\times10^5, 1x,sx,txN1 \le x, sx, tx \le N, 1y,sy,tyM1 \le y,sy,ty \le M, 0v<11451410 \le v < 1145141. The input maze contains only # and digit characters.

Test point number N,MN,M \le Special property
121\sim 2 22 B
343\sim 4 500500 A
565\sim 6 B,C
787\sim 8 C
9119\sim 11 B,D
121312\sim 13 D
141714\sim 17 B
182018\sim 20 None

Special property A: For each query, either no valid solution exists, or there exists a solution of no more than 55 steps.

Special property B: There is no operation 1.

Special property C: At any time, for all Non-Thunder Blocked Area cells, the digit on the cell is 00.

Special property D: At any time, for all Non-Thunder Blocked Area cells, the digits on the cells are the same.

Translated by ChatGPT 5