#abc331d. D - Tile Pattern
D - Tile Pattern
Score : points
问题描述
存在一个 行乘以 列的网格。令 表示从上到下第 行、从左到右第 列的方格(注意不寻常的索引分配,)。
每个方格为黑色或白色。方格 的颜色由字符 P\[i \bmod N\]\[j \bmod N\] 表示,其中 B
表示黑色,W
表示白色。这里, 表示 除以 后的余数。
请回答 个查询请求。
每个查询提供四个整数 ,并询问在以 为左上角、 为右下角的矩形区域内,包含多少个黑色方格。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with by squares. Let denote the square at the -th row from the top and the -th column from the left . (Note the unusual index assignment.)
Each square is black or white. The color of the square is represented by a character P\[i \bmod N\]\[j \bmod N\], where B
means black, and W
means white. Here, denotes the remainder when is divided by .
Answer queries.
Each query gives you four integers and asks you to find the number of black squares contained in the rectangular area with as the top-left corner and as the bottom-right corner.
Constraints
- P\[i\]\[j\] is
W
orB
. - are all integers.
Input
The input is given from Standard Input in the following format. Here, is the -th query to be processed.
P\[0\]\[0\]P\[0\]\[1\]\dots P\[0\]\[N-1\]
P\[1\]\[0\]P\[1\]\[1\]\dots P\[1\]\[N-1\]
P\[N-1\]\[0\]P\[N-1\]\[1\]\dots P\[N-1\]\[N-1\]
Each query is given in the following format:
Output
Follow the instructions in the problem statement and print the answers to the queries, separated by newlines.
Sample Input 1
3 2
WWB
BBW
WBW
1 2 3 4
0 3 4 5
Sample Output 1
4
7
The figure below illustrates the upper left part of the grid.
For the first query, the rectangular area with as the top-left corner and as the bottom-right corner, surrounded by the red frame in the figure, contains four black squares.
For the second query, the rectangular area with as the top-left corner and as the bottom-right corner, surrounded by the blue frame in the figure, contains seven black squares.
Sample Input 2
10 5
BBBWWWBBBW
WWWWWBBBWB
BBBWBBWBBB
BBBWWBWWWW
WWWWBWBWBW
WBBWBWBBBB
WWBBBWWBWB
WBWBWWBBBB
WBWBWBBWWW
WWWBWWBWWB
5 21 21 93
35 35 70 43
55 72 61 84
36 33 46 95
0 0 999999999 999999999
Sample Output 2
621
167
44
344
500000000000000000
update @ 2024/3/10 01:15:35