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

#FT0000169. Cộng hình chữ nhật và hỏi giá trị tại điểm (Rectangle Add Point Get)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cộng hình chữ nhật và hỏi giá trị tại điểm (Rectangle Add Point Get)

Rectangle Add Point Get

Source: Library Checker

Version: Phước Hưng OJ Extended.

Problem Statement

Initially, there are NN weighted rectangles [l,r)×[d,u)[l,r)\times[d,u). A rectangle of weight ww contributes ww to every integer point within it. Overlapping rectangles contribute additively. Process QQ operations in order:

  • 0 l d r u w: insert an additional weighted rectangle.
  • 1 x y: return the sum of weights of all previously inserted rectangles, including the initial ones, that contain (x,y)(x,y).

Each rectangle is half-open, with l≤x<rl\le x<r and d≤y<ud\le y<u. Rectangles are never removed or edited.

Input

The first line contains N,QN,Q, followed by NN lines l d r u w describing the initial rectangles, then QQ operations 0 l d r u w or 1 x y.

Output

For each 1 x y operation, print the accumulated weight at (x,y)(x,y) on a separate line.

Subtask

  • Subtask 1 (20 points): 1≤N≤201\le N\le 20; 1≤Q≤401\le Q\le 40; every rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9, 0≤w≤1090\le w\le10^9; query points have 0≤x,y≤1090\le x,y\le10^9.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le 2000; 1≤Q≤30001\le Q\le 3000; every rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9, 0≤w≤1090\le w\le10^9; query points have 0≤x,y≤1090\le x,y\le10^9.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Q≤2000001\le Q\le 200000; every rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9, 0≤w≤1090\le w\le10^9; query points have 0≤x,y≤1090\le x,y\le10^9.

Examples

Example 1

Input

2 5
0 0 3 3 2
2 2 5 5 4
1 1 1
1 2 2
0 1 1 4 4 3
1 2 2
1 4 4

Output

2
6
9
4

Explanation

Point (1,1)(1,1) lies only in the first rectangle and receives 2. Point (2,2)(2,2) lies in both initial rectangles, giving 2+4=62+4=6. Adding [1,4)×[1,4)[1,4)\times[1,4) with weight 3 makes its value 99. Point (4,4)(4,4) belongs only to the second initial rectangle; it is excluded from the newly added rectangle by the half-open upper and right boundaries, giving 4.

Example 2

Input

1 5
0 0 2 2 7
1 0 0
0 0 0 2 2 5
1 1 1
1 2 1
1 0 2

Output

7
12
0
0

Explanation

Initially, (0,0)(0,0) receives 7. Adding an identical rectangle of weight 5 makes the value at (1,1)(1,1) equal to 7+5=127+5=12. Points (2,1)(2,1) and (0,2)(0,2) lie on excluded right or upper boundaries, so their values are both zero.