#FT0000219. Hệ thống định vị Mokia (Mokia - Dynamic Rectangle)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 unit cells. Each cell has integer coordinates , both numbered from to . Initially, every cell contains users.
The system receives commands, executed sequentially in their given order. There are two command types:
1 x y a: add exactly users to cell , 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 and .
Print the result of each type- command in the order the commands are executed. Queries do not change the state. Let and denote the numbers of type- and type- commands, respectively, so .
Input
- The first line contains : the grid side length and the number of commands.
- Each of the following exactly lines gives one command in chronological order:
1 x y aspecifies an update, its cell coordinates, and the positive increment.2 x1 y1 x2 y2specifies a query rectangle by its opposite corners.
Output
For each type- command, print one line with the number of users in its rectangle at the moment it is executed. Print nothing for type- commands. If there are no type- commands, produce no output.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; ; ; ; .
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 grid initially contains no users.
1 2 3 3adds users at .2 1 1 3 3asks about . The cell lies inside, so the answer is .1 2 2 2adds users at . The two nonempty cells now contain and users.2 2 2 3 4asks about , which includes both nonempty cells; the answer is .
Therefore the two output lines are 3 and 5.