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

#FT0000219. Hệ thống định vị Mokia (Mokia - Dynamic Rectangle)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hệ thống định vị Mokia (Mokia - Dynamic Rectangle)

Mokia - Dynamic Rectangle

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

The Mokia mobile phone company manages a square area divided into w×ww\times w unit cells. Each cell has integer coordinates (x,y)(x,y), both numbered from 11 to ww. Initially, every cell contains 00 users.

The system receives qq commands, executed sequentially in their given order. There are two command types:

  • 1 x y a: add exactly aa users to cell (x,y)(x,y), leaving all other cells unchanged. A cell may be updated more than once.
  • 2 x1 y1 x2 y2: return the current total number of users in all cells of the inclusive rectangle x1≤x≤x2x_1\le x\le x_2 and y1≤y≤y2y_1\le y\le y_2.

Print the result of each type-22 command in the order the commands are executed. Queries do not change the state. Let uu and vv denote the numbers of type-11 and type-22 commands, respectively, so u+v=qu+v=q.

Input

  • The first line contains w,qw,q: the grid side length and the number of commands.
  • Each of the following exactly qq lines gives one command in chronological order:
    • 1 x y a specifies an update, its cell coordinates, and the positive increment.
    • 2 x1 y1 x2 y2 specifies a query rectangle by its opposite corners.

Output

For each type-22 command, print one line with the number of users in its rectangle at the moment it is executed. Print nothing for type-11 commands. If there are no type-22 commands, produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤w≤201\le w\le20; 1≤q≤151\le q\le15; 0≤u≤100\le u\le10; 0≤v≤50\le v\le5; u+v=qu+v=q; 1≤x,y,x1,y1,x2,y2≤w1\le x,y,x_1,y_1,x_2,y_2\le w; x1≤x2x_1\le x_2; y1≤y2y_1\le y_2; 1≤a≤1041\le a\le10^4.
  • Subtask 2 (30 points): 1≤w≤2⋅1041\le w\le2\cdot10^4; 1≤q≤20001\le q\le2000; 0≤u≤16000\le u\le1600; 0≤v≤4000\le v\le400; u+v=qu+v=q; 1≤x,y,x1,y1,x2,y2≤w1\le x,y,x_1,y_1,x_2,y_2\le w; x1≤x2x_1\le x_2; y1≤y2y_1\le y_2; 1≤a≤1041\le a\le10^4.
  • Subtask 3 (50 points): 1≤w≤2⋅1061\le w\le2\cdot10^6; 1≤q≤1700001\le q\le170000; 0≤u≤1600000\le u\le160000; 0≤v≤100000\le v\le10000; u+v=qu+v=q; 1≤x,y,x1,y1,x2,y2≤w1\le x,y,x_1,y_1,x_2,y_2\le w; x1≤x2x_1\le x_2; y1≤y2y_1\le y_2; 1≤a≤1041\le a\le10^4.

Examples

Input

4 4
1 2 3 3
2 1 1 3 3
1 2 2 2
2 2 2 3 4

Output

3
5

Explanation

The 4×44\times4 grid initially contains no users.

  • 1 2 3 3 adds 33 users at (2,3)(2,3).
  • 2 1 1 3 3 asks about [1,3]×[1,3][1,3]\times[1,3]. The cell (2,3)(2,3) lies inside, so the answer is 33.
  • 1 2 2 2 adds 22 users at (2,2)(2,2). The two nonempty cells now contain 33 and 22 users.
  • 2 2 2 3 4 asks about [2,3]×[2,4][2,3]\times[2,4], which includes both nonempty cells; the answer is 3+2=53+2=5.

Therefore the two output lines are 3 and 5.