A. 雪原遗迹的二进制密码

    传统题 5000ms 512MiB

雪原遗迹的二进制密码

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Background

Muxue youth discovers a series of ancient stone tablets in the snowfield ruins, each engraved with a mysterious binary number. These tablets are arranged according to some pattern, forming a massive binary matrix.

According to murals found in the ruins, these tablets are part of an ancient encryption system. To decode the cipher, one must find all the "perfect binary squares" in the matrix—square submatrices whose four corner digits satisfy a specific XOR relationship.

Problem Description

Given an n×mn \times m binary matrix AA, where each element is either 0 or 1, define a perfect binary square as a square submatrix that satisfies the following conditions:

Let the side length of the square be kk (k2k \geq 2), and let its top-left corner coordinates be (i,j)(i, j). Then the four corner coordinates are:

  • Top-left: (i,j)(i, j)
  • Top-right: (i,j+k1)(i, j + k - 1)
  • Bottom-left: (i+k1,j)(i + k - 1, j)
  • Bottom-right: (i+k1,j+k1)(i + k - 1, j + k - 1)

Condition: The values a,b,c,da, b, c, d at these four positions must satisfy:

(ab)(cd)=1(a \oplus b) \oplus (c \oplus d) = 1

where \oplus denotes the XOR operation.

You need to answer qq queries. Each query specifies a rectangular region [x1,y1,x2,y2][x_1, y_1, x_2, y_2] and asks how many perfect binary squares are fully contained within this region (i.e., all points of the square lie within the query region).

Input Format

The input contains multiple test cases. The first line contains an integer TT (1T101 \leq T \leq 10), indicating the number of test cases.

The format for each test case is as follows:

  1. The first line contains three integers n,m,qn, m, q (1n,m10001 \leq n, m \leq 1000, 1q1051 \leq q \leq 10^5)
  2. The next nn lines each contain a string of length mm, representing the binary matrix. The jj-th character of the ii-th line denotes Ai,jA_{i,j} ('0' or '1')
  3. The next qq lines each contain four integers x1,y1,x2,y2x_1, y_1, x_2, y_2 (1x1x2n1 \leq x_1 \leq x_2 \leq n, 1y1y2m1 \leq y_1 \leq y_2 \leq m), representing a query

Output Format

For each query, output a single integer on a line, indicating the number of perfect binary squares within the region.

Sample Input

1
4 4 3
0101
1010
0101
1010
1 1 4 4
1 1 3 3
2 2 4 4

Sample Output

0
0
0

Explanation

Sample Explanation

Matrix:

0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0

Perfect binary square condition: (ab)(cd)=1(a \oplus b) \oplus (c \oplus d) = 1

Query 1: Entire matrix

  • Squares with side length 2:
    • (1,1): 0,1,1,0 → (0⊕1)⊕(1⊕0)=1⊕1=0
    • (1,2): 1,0,0,1 → 1⊕1=0
    • (1,3): 0,1,1,0 → 0
    • (2,1): 1,0,0,1 → 0
    • (2,2): 0,1,1,0 → 0
    • (2,3): 1,0,0,1 → 0
  • Squares with side length 3:
    • (1,1): 0,0,0,0 → 0
    • (1,2): 1,1,1,1 → 0
    • (2,1): 1,1,1,1 → 0
    • (2,2): 0,0,0,0 → 0
  • Squares with side length 4:
    • (1,1): 0,1,1,0 → 0

The condition can be simplified as: abcd=1a \oplus b \oplus c \oplus d = 1

Note: The sample output may be based on other matrices satisfying the condition. In actual tests, ensure the correct test data is used.

Global Constraints

For all data:

  • 1T101 \leq T \leq 10
  • The total sum of n×mn \times m across all test cases does not exceed 2×1062 \times 10^6
  • The total sum of qq across all test cases does not exceed 2×1052 \times 10^5
  • Matrix elements are only '0' or '1'

Subtasks

  • Subtask 1 (20 points): n,m50n, m \leq 50, q100q \leq 100
  • Subtask 2 (30 points): n,m200n, m \leq 200, q1000q \leq 1000
  • Subtask 3 (30 points): n,m500n, m \leq 500, q5000q \leq 5000
  • Subtask 4 (20 points): No additional restrictions

【XJS-C5-Div2】XJSOI 春节大月赛 Round 3 & 勰码可达鸭合作赛 Round 1

未参加
状态
已结束
规则
IOI
题目
5
开始于
2026-2-14 0:00
结束于
2026-2-17 0:00
持续时间
5 小时
主持人
参赛人数
4