問題一覧 > 通常問題

No.3207 Digital Font

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 29
作問者 : amesyu / テスター : noshinn lmorinn 👑 qand
お気に入りにしたユーザー ProblemId : 12500 / 自分の提出
問題文最終更新日: 2025-07-19 00:18:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 474 (順位表) の他の問題:

Story


In a font like the one in the image above, 0,1,2,5,8 are point-symmetric, so they do not change when rotated by 180 degrees.
On the other hand, 6,9 change into 9,6 respectively when rotated by 180 degrees. 3,4,7 can't be read at all, can they~

Problem Statement

There is a matrix $A$ with $H$ rows and $W$ columns. $A_{i,j}$ denotes the value in row $i$ and column $j$.
The elements of $A$ satisfy $A_{i_k, j_k} = x_k$ for $k = 1, 2 \cdots, N$, and all other elements are $0$.
$Q$ queries are given in the following format. Process them in order.

  • Each query is given in the format l d r u. Print Yes if the submatrix of $A$ consisting of the elements with rows in the range from $l$ to $r$ and columns in the range from $d$ to $u$ is point-symmetric, and No otherwise.
Definition of a point-symmetric matrix
  • Define the function $f(x)$, which rotates $x \ ( x \in \{0, 1, 2, 5, 6, 8, 9 \} )$ by $180$ degrees, as follows.
    $$ f(x) = \begin{cases} 0 & \text{if } x = 0 \\ 1 & \text{if } x = 1 \\ 2 & \text{if } x = 2 \\ 5 & \text{if } x = 5 \\ 9 & \text{if } x = 6 \\ 8 & \text{if } x = 8 \\ 6 & \text{if } x = 9 \end{cases} $$ Using $f(x)$ defined in this way, print Yes if $A_{i, j} = f(A_{r+l-i, u+d-j})$ holds for all $(i, j) \ (l \leq i \leq r, d \leq j \leq u)$, and No otherwise.

Constraints

  • $1 \leq H, W \leq 10^5$
  • $0 \leq N \leq \text{min}(HW, 10^5)$
  • $1 \leq i_k \leq H$
  • $1 \leq j_k \leq W$
  • $x_k \in \{0, 1, 2, 5, 6, 8, 9 \}$
  • The pairs $(i_k, j_k)$ are distinct
  • $1 \leq Q \leq 10^5$
  • $1 \leq l \leq r \leq H$
  • $1 \leq d \leq u \leq W$
  • All inputs are integers

Input

$H$ $W$
$N$
$i_1$ $j_1$ $x_1$
$i_2$ $j_2$ $x_2$
$\vdots$
$i_N$ $j_N$ $x_N$
$Q$
$l_1 \ d_1 \ r_1 \ u_1$
$l_2 \ d_2 \ r_2 \ u_2$
$\vdots$
$l_Q \ d_Q \ r_Q \ u_Q$

Output

Print $Q$ lines. On the $i$-th line, print the answer to the $i$-th query.

Sample

Sample 1
Input
5 7
14
1 1 2
1 3 6
1 4 9
1 5 8
3 1 1
3 2 5
3 4 5
3 5 1
3 7 2
5 1 8
5 2 6
5 3 9
5 5 2
5 7 1
7
1 1 5 5
1 1 5 7
3 5 5 7
2 2 2 7
1 3 5 3
5 1 5 1
1 5 3 5
Output
Yes
No
Yes
Yes
Yes
Yes
No

Sample 2
Input
100000 100000
0
1
1 1 100000 100000
Output
Yes

$N = 0$ is also possible.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。