DS Team Selection
Time limit18sMemory limit1024 MB
Each update adds a square pyramid of weights centered at (x, y), and each query asks for the weight sum over a rectangle modulo 2^30.
- Level
Hard9 of 10
- Topics
- Segment tree, Math, Implementation
- Solved
- No attempts yet
Problem
The 34th International Olympiad in Data Structures will take place soon. In order to qualify, you need to pass the team selection contest in your country. As a member of the Cat team, you have to solve this problem in the Cat Team Selection contest.
There are infinitely many points with integer coordinates on an infinite plane, each of which can be represented as . Initially, the weights of all points are . You need to perform operations, each of which takes the form:
1: For all points that satisfy and , increase their point weights by .2: Print the sum of the weights of points that satisfy and . Since the sum can be large, output it modulo .
Input
The first line contains a single integer (), the number of operations.
The next lines each contain several integers in one of the following forms:
1()2(, )
Output
For each operation of type 2, print a single line containing the requested sum of the weights. Print it modulo .