PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000212. Lưới gạch tuần hoàn (Tile Pattern)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lưới gạch tuần hoàn (Tile Pattern)
Tile Pattern
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A grid has rows and columns, indexed from 0. A repeating tile uses B for black and W for white. Cell has color . For each query , count black cells in rows through and columns through , inclusive.
Input
The first line contains . The next lines each contain exactly characters B or W. Each of the next lines contains four integers .
Output
Print lines, one black-cell count per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; each tile cell is
BorW. - Subtask 2 (30 points): ; ; ; ; each tile cell is
BorW; . - Subtask 3 (50 points): ; ; ; ; each tile cell is
BorW.
Example 1
Input
3 2
WWB
BBW
WBW
1 2 3 4
0 3 4 5
Output
4
7
Explanation
The first rectangle contains 4 black cells, the second 7. Rows and columns repeat with period 3.
Example 2
Input
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
Output
621
167
44
344
500000000000000000
Explanation
The first four counts are 621, 167, 44 and 344. The 10×10 tile has 50 black cells, and the final query consists of whole tiles.