Mokia
Time limit1sMemory limit128 MB
Point updates add customers to grid cells and each query asks for the total inside a rectangle using only earlier updates.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Segment tree
- Solved
- No attempts yet
Problem
The Moldovan mobile phone company Mokia has built a new customer location system. Like other location systems it answers a query of the form "Where is customer C?" with millimeter precision, and it also answers a query of the form "How many customers are inside a given rectangular area?".
The system treats the world as a square of size that is divided into cells of size . A cell is named by a pair of indices with . Indexing starts at 1, so a table of size has and .

Write a program that reports how many customers are inside a given rectangular area.
Input
Each instruction is on its own line and consists of one instruction integer followed by its parameters.
A query counts only the add instructions that come before it in the input. Print nothing for a line whose instruction is not 2.
Output
For every instruction 2, print the requested number of customers on its own line, in the order the queries are given.
Constraints
- The number of instruction 1 lines is at most 160,000.
- The number of instruction 2 lines is at most 10,000.