#FT0000164. Đếm điểm trong hình chữ nhật (Points in Rectangle)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm điểm trong hình chữ nhật (Points in Rectangle)
Points in Rectangle
Source: LightOJ
Version: Phuoc Hung OJ – outputs contain query answers without a Case header.
Problem Statement
Initially the integer plane contains no stored points. Process operations; a stored point is uniquely identified by its coordinates:
0 x y: insert point . If it is already present, do nothing.1 x1 y1 x2 y2: count distinct stored locations in the closed rectangle , (including boundaries).
Queries account only for points inserted so far.
Input
The first line contains , followed by commands of the form 0 x y or 1 x1 y1 x2 y2.
Output
For each type-1 query, print the count of distinct stored points in the rectangle, one line per query.
Subtasks
- Subtask 1 (20 points): ; all coordinates are integers in ; insertion has ; a query has and ; duplicate insertions have no effect.
- Subtask 2 (30 points): ; all coordinates are integers in ; insertion has ; a query has and ; duplicate insertions have no effect.
- Subtask 3 (50 points): ; all coordinates are integers in ; insertion has ; a query has and ; duplicate insertions have no effect.
Examples
Example 1
Input
4
0 1 1
0 2 6
1 1 1 6 6
1 2 2 5 5
Output
2
0
Explanation
Two points are inserted: (1,1) and (2,6). Both lie in the first inclusive rectangle, so the answer is 2. Neither lies in the second rectangle, whose coordinates satisfy and ; the answer is 0.
Example 2
Input
6
0 1 1
0 1 1
0 0 0
1 0 0 1 1
0 2 2
1 1 1 2 2
Output
2
2
Explanation
Inserting (1,1) twice stores only one point. With (0,0) inserted, the first rectangle contains two distinct locations. After inserting (2,2), the second rectangle, from (1,1) to (2,2), also contains two stored points.