#FT0000165. Đếm số ô có màu chỉ định (Counting Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm số ô có màu chỉ định (Counting Problem)
Counting Problem
Source: Luogu
Version: Phuoc Hung OJ – standard input format, original problem semantics preserved.
Problem Statement
An grid initially assigns a color to each cell. Row and column indices are one-based. Process operations:
1 x y c: change the color of cell to , replacing its former color.2 x1 x2 y1 y2 c: count cells with color exactly among rows through and columns through , inclusive.
For type 2, the two row bounds precede the two column bounds.
Input
The first line gives . The next lines contain initial colors each. The next line gives , followed by operations of the form 1 x y c or 2 x1 x2 y1 y2 c.
Output
For every type-2 query, print the number of cells of color in the rectangle, one line per query.
Subtasks
- Subtask 1 (30 points): ; ; ; all colors lie in ; type-
1coordinates , ; type-2bounds , . - Subtask 2 (70 points): ; ; ; all colors lie in ; type-
1coordinates , ; type-2bounds , .
Examples
Example 1
Input
2 3
1 2 1
2 3 1
6
2 1 2 1 3 1
1 1 2 1
2 1 1 1 3 1
2 1 2 2 3 2
1 2 1 1
2 1 2 1 3 1
Output
3
3
0
5
Explanation
Initially color 1 appears at (1,1), (1,3), (2,3), count 3. Recoloring (1,2) makes all three cells in the first row color 1. No color-2 cells remain in columns 2–3, giving 0. Recoloring (2,1) adds another color-1 cell, resulting in five overall.
Example 2
Input
1 1
100
4
2 1 1 1 1 100
1 1 1 3
2 1 1 1 1 100
2 1 1 1 1 3
Output
1
0
1
Explanation
The single cell initially has color 100, so the first query returns 1. Recoloring it to 3 removes the only occurrence of color 100 (answer 0) and creates one color-3 cell (answer 1).