雪原遗迹的二进制密码
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
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 binary matrix , 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 (), and let its top-left corner coordinates be . Then the four corner coordinates are:
- Top-left:
- Top-right:
- Bottom-left:
- Bottom-right:
Condition: The values at these four positions must satisfy:
where denotes the XOR operation.
You need to answer queries. Each query specifies a rectangular region 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 (), indicating the number of test cases.
The format for each test case is as follows:
- The first line contains three integers (, )
- The next lines each contain a string of length , representing the binary matrix. The -th character of the -th line denotes ('0' or '1')
- The next lines each contain four integers (, ), 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:
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:
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:
- The total sum of across all test cases does not exceed
- The total sum of across all test cases does not exceed
- Matrix elements are only '0' or '1'
Subtasks
- Subtask 1 (20 points): ,
- Subtask 2 (30 points): ,
- Subtask 3 (30 points): ,
- Subtask 4 (20 points): No additional restrictions
【XJS-C5-Div1】XJSOI 春节大月赛 Round 3 & 勰码可达鸭合作赛 Round 1
- 状态
- 已结束
- 规则
- IOI
- 题目
- 5
- 开始于
- 2026-2-17 0:00
- 结束于
- 2026-2-24 0:00
- 持续时间
- 168 小时
- 主持人
- 参赛人数
- 5