#C3355. Circular Array Operations

    ID: 46773 Type: Default 1000ms 256MiB

Circular Array Operations

Circular Array Operations

Problem Statement:

You are given a circular array \(A\) consisting of \(N\) elements, initially all set to zero. You need to perform \(M\) operations on the array. There are two types of operations:

  • Update Operation: 1 L R X - Add an integer \(X\) to every element in the range from index \(L\) to index \(R\) (inclusive). (1-indexed)
  • Query Operation: 2 L R - Compute and output the sum of the elements in the range from index \(L\) to index \(R\) (inclusive).

The operations are executed sequentially. Although the array is described as circular, note that the operations do not wrap around the boundary of the array.

Please use standard input and output for all interactions.

inputFormat

Input Format:

The first line contains two integers, \(N\) and \(M\), where \(N\) is the size of the array and \(M\) is the number of operations.

Each of the next \(M\) lines contains an operation in one of the following formats:

  • 1 L R X for an update operation.
  • 2 L R for a query operation.

outputFormat

Output Format:

For every query operation, output the resulting sum on a new line.

## sample
5 2
1 1 3 10
2 1 3
30