Division Queries and Updates

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.5s
Memory limit: 256M

Author:
Problem types

You are given an array A of size N, with all elements initially equal to 0. Support the following operations:

  • Type 1: Given l and r, increment all Ai with lir by 1.
  • Type 2: Given l and r, return the sum of all Aii for lir.

Constraints

For all subtasks:

1N109

1Q2×105

1ti2

1liriN

Subtask 1 [20%]

1N,Q2000

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains 2 integers N and Q, the size of the array and the number of operations to be performed.

The next Q lines each contain 3 integers ti,li,ri (1iQ), the type number of the ith operation and the parameters l and r for that operation.

Output Specification

For each operation of type 2 output an integer on its own line, the return value of the operation.

Sample Input

Copy
8 8
2 1 8
1 1 4
2 1 2
2 2 8
1 2 3
1 2 7
1 2 8
2 1 8

Sample Output

Copy
0
1
0
4

Explanation

Right before the last operation, A=[1,4,4,3,2,2,2,1]. The sum of all Aii for 1i8 is 1+2+1+0+0+0+0+0=4.


Comments

There are no comments at the moment.