QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 512 MB Total points: 100

#604. Sum 6

統計

Given a sequence $A_{0,1}, A_{0,2}, \cdots, A_{0,n}$ with the length $n$. Initially, the value of the integer $c$ is $0$. You need to process the following $m$ queries:

  • 1 l r x:
    • For each $1 \le i \le n$, Let $A_{c+1,i} \leftarrow A_{c,i}$.
    • For each $l \leq i \leq r$, let $A_{c+1,i} \leftarrow A_{c+1,i} + x$.
    • Let $c \leftarrow c+1$.
  • 2 l r: Print the sum of the historical value of $A_i$ when $l \leq i \leq r$. That is, print $\sum_{k=0}^c \sum_{i=l}^r A_{k,i}$.

Input

The first line of the input contains two integers $n$ and $m$ - the length of the sequence and the number of the operations.

The next line of the input contains $n$ integers $A_{0,1}, A_{0,2}, \cdots, A_{0,n}$, describes the sequence $A$ at the initial time.

The next $m$ lines of the input describe one query per line.

Output

For each query of type 2, you need to output a line with a single integer indicating the answer.

Samples

Input 1

1 9
2
1 1 1 2
2 1 1
1 1 1 3
1 1 1 1
2 1 1
1 1 1 4
1 1 1 -2
1 1 1 -3
2 1 1

Output 1

6
21
50

Input 2

6 8
5 -2 4 -7 3 -5
2 2 5
1 1 4 -2
1 2 5 3
1 1 3 2
2 1 4
1 2 5 4
1 4 6 3
2 3 6

Output 2

-2
0
25

Scoring

It is guaranteed that $1 \leq n,m \leq 2 \times 10^5, -10^9 \leq A_i \leq 10^9, 1 \leq l \leq r \leq n, -10^9 \leq x \leq 10^9$.

  • Subtask 1(10 points): $1 \leq n,m \leq 5000$
  • Subtask 2(30 points): for the query of type 1, we have $l = r$.
  • Subtask 3(30 points): for the query of type 2, we have $l = r$.
  • Subtask 4(30 ponits): no additional constraints.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.