QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#8229. Stack

统计

There are $n$ stacks, numbered from $1$ to $n$. There are $m$ operations of three types:

  • $1\ l\ r\ x\ y$: Push $x$ copies of $y$ onto each stack with an index in the range $[l, r]$.
  • $2\ l\ r\ w$: Perform the pop operation $w$ times on each stack with an index in the range $[l, r]$. If a stack is empty, do nothing; otherwise, remove the top element.
  • $3\ k\ p\ q$: Query the sum of elements from the $p$-th to the $q$-th position (inclusive) in stack $k$, counting from the bottom. If the $i$-th element does not exist in the stack, treat it as $0$.

Input

The first line contains two integers $n$ and $m$.

Each of the next $m$ lines describes an operation in the following format:

  • $1\ l\ r\ x\ y$: Push $x$ copies of $y$ onto each stack with an index in the range $[l, r]$.
  • $2\ l\ r\ w$: Perform the pop operation $w$ times on each stack with an index in the range $[l, r]$.
  • $3\ k\ p\ q$: Query the sum of elements from the $p$-th to the $q$-th position in stack $k$.

Output

For each query, output a single integer representing the answer.

Examples

Input 1

4 8
1 1 3 3 2
1 2 4 2 1
3 1 2 4
3 2 2 4
2 2 3 1
2 1 2 2
3 1 1 1
3 2 2 3

Output 1

4
5
2
2

Subtasks

For all data, $1\le n,m\le 10^5, 1\le x,y\le 10^5, 1\le w\le 10^{10}, 1\le p\le q\le 10^{10}$.

  • Subtask 1 (18 pts): $n, m \le 5000$.
  • Subtask 2 (21 pts): Guaranteed that no type $2$ operations occur.
  • Subtask 3 (16 pts): For all type $1$ operations, $y=1$ is guaranteed.
  • Subtask 4 (24 pts): For all type $3$ operations, $p=1, q=10^{10}$ is guaranteed.
  • Subtask 5 (21 pts): No special restrictions.

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.