PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000164. Đếm điểm trong hình chữ nhật (Points in Rectangle)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đế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 QQ operations; a stored point is uniquely identified by its coordinates:

  • 0 x y: insert point (x,y)(x,y). If it is already present, do nothing.
  • 1 x1 y1 x2 y2: count distinct stored locations in the closed rectangle x1≤x≤x2x1\le x\le x2, y1≤y≤y2y1\le y\le y2 (including boundaries).

Queries account only for points inserted so far.

Input

The first line contains QQ, followed by QQ 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): 1≤Q≤601\le Q\le 60; all coordinates are integers in [0,20][0,20]; insertion has 0≤x,y≤200\le x,y\le20; a query has 0≤x1<x2≤200\le x1<x2\le20 and 0≤y1<y2≤200\le y1<y2\le20; duplicate insertions have no effect.
  • Subtask 2 (30 points): 1≤Q≤20001\le Q\le 2000; all coordinates are integers in [0,200][0,200]; insertion has 0≤x,y≤2000\le x,y\le200; a query has 0≤x1<x2≤2000\le x1<x2\le200 and 0≤y1<y2≤2000\le y1<y2\le200; duplicate insertions have no effect.
  • Subtask 3 (50 points): 1≤Q≤300001\le Q\le 30000; all coordinates are integers in [0,1000][0,1000]; insertion has 0≤x,y≤10000\le x,y\le1000; a query has 0≤x1<x2≤10000\le x1<x2\le1000 and 0≤y1<y2≤10000\le y1<y2\le1000; 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 2≤x≤52\le x\le5 and 2≤y≤52\le y\le5; 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.