AT_aalc001_r 連結性
Description
There is a grid with $ N $ rows and $ W $ columns. Let cell $ (i,j) $ denote the cell in the $ i $ -th row from the top and the $ j $ -th column from the left.
Each cell of the grid contains $ 1 $ digit. Initially, cell $ (i,j) $ contains the $ j $ -th character of the string $ S_i $ .
Process $ Q $ queries. Each query is of one of the following $ 2 $ types:
- `1 i T`: For $ j=1,2,\ldots,W $ , change the digit in cell $ (i,j) $ to the $ j $ -th character of $ T $ .
- `2 a b c d`: Determine whether you can reach cell $ (c,d) $ from cell $ (a,b) $ by repeatedly moving to a cell that shares an edge with the current cell and contains the same digit as the current cell.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ W $ $ Q $ $ S_1 $ $ S_2 $ $ \vdots $ $ S_N $ $ \mathrm{query}_1 $ $ \mathrm{query}_2 $ $ \vdots $ $ \mathrm{query}_Q $
Each query is given in one of the following formats:
> $ 1 $ $ i $ $ T $
> $ 2 $ $ a $ $ b $ $ c $ $ d $
Output Format
Let $ q $ be the number of type $ 2 $ queries. Print $ q $ lines. On the $ j $ -th line, print `Yes` if the destination can be reached in the $ j $ -th type $ 2 $ query, and `No` otherwise.
Explanation/Hint
### Sample Explanation 1
Initially, you can reach cell $ (2,5) $ from cell $ (1,1) $ by passing only through cells containing the digit $ 0 $ . However, you cannot reach cell $ (4,1) $ from cell $ (1,1) $ .
After changing row $ 3 $ to `00000`, you can reach cell $ (4,1) $ from cell $ (1,1) $ .
### Sample Explanation 2
You can reach cell $ (3,7) $ from cell $ (4,1) $ by moving in the following order, for example:
\\\[ (4,1),(3,1),(2,1),(1,1),(1,2),(1,3),(2,3),(3,3),(3,4),(3,5),(2,5),(1,5),(1,6),(1,7),(2,7),(3,7) \\\]
### Constraints
- $ 2 \le N \le 10^5 $
- $ 2 \le W \le 10 $
- $ 1 \le Q \le 5 \times 10^4 $
- $ S_i $ is a string of length $ W $ consisting of digits.
- For type $ 1 $ queries, $ 1 \le i \le N $
- For type $ 1 $ queries, $ T $ is a string of length $ W $ consisting of digits.
- For type $ 2 $ queries, $ 1 \le a,c \le N $ , $ 1 \le b,d \le W $
- For type $ 2 $ queries, $ (a,b) \ne (c,d) $
- When a type $ 2 $ query is given, cells $ (a,b) $ and $ (c,d) $ contain the same digit.
- All numerical values in the input are integers.