QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#4258. Hand of God

统计

The Hand of God manipulates four-dimensional space. Suppose there are $n$ days of interest to God in this four-dimensional space. Let $x_i$ be the chaos level of a three-dimensional world at the end of day $i$. Due to natural causes, the chaos level of the world increases by $d_i$ on day $i$. However, to maintain the balance of the world, there is an upper bound $l_i$ for the chaos level each day, such that $x_i = \min\{x_{i-1}+d_i , l_i\}$.

God wishes to perform a series of tests on this four-dimensional space and asks you to build a model. Specifically, there are three types of tests:

  1. Given $a, b$, and $k$, for all $c$ such that $a \leq c \leq b$, let the world evolve starting from day $c$ with an initial chaos level of $l_{c-1}$, and write down the chaos level $x_b$ at the end of day $b$. You need to tell God the $k$-th largest $x_b$ on the paper. It is guaranteed that $1 \leq a \leq b \leq n$ and $1 \leq k \leq b - a + 1$.
  2. Given $a, b$, and $x_0$, for all $c$ such that $a \leq c \leq b$, let the world evolve starting from day $c$ with an initial chaos level of $x_0$, and write down the chaos level $x_b$ at the end of day $b$. You need to tell God the maximum $x_b$ on the paper. (Note: $x_0$ may be greater than $l_{c-1}$). It is guaranteed that $1 \leq a \leq b \leq n$.
  3. Given $a$ and $b$, for all $c$ such that $a \leq c \leq b$, let the world evolve starting from day $c$ with an initial chaos level of $l_{c-1}$, and write down the chaos level $x_b$ at the end of day $b$. You need to tell God how many distinct values of $x_b$ are on the paper. It is guaranteed that $1 \leq a \leq b \leq n$.

Of course, God will also modify $l_i$ at certain positions. Can you successfully help God complete the tests?

Input

The first line contains two positive integers $n$ and $m$, representing the total number of days and the total number of operations (including tests and modifications), respectively.

The second line contains $n$ non-negative integers $d_1, \dots, d_n$.

The third line contains $n+1$ non-negative integers $l_0, \dots, l_n$. See the problem description for their meanings.

Starting from the fourth line, there are $m$ lines, each starting with an integer $\mathrm{type}$ representing the operation type.

If $\mathrm{type}=0$, it is followed by two integers $u$ and $x$, indicating that $l_u$ is changed to $x$. It is guaranteed that $0 \leq u \leq n$.

If $\mathrm{type}>0$, $\mathrm{type}$ corresponds to the test type number described in the problem. When $\mathrm{type} = 1$, it is followed by three integers $a, b$, and $k$; when $\mathrm{type} = 2$, it is followed by three integers $a, b$, and $x_0$; when $\mathrm{type} = 3$, it is followed by two integers $a$ and $b$. See the problem description for specific meanings.

Output

For each test, output one line containing an integer representing the test result.

Examples

Input 1

3 5
2 1 3
2 6 7 5
1 1 2 2
3 1 3
0 3 15
3 1 3
2 1 3 2

Output 1

5
1
2
8

Constraints

For the first 10% of the data, $n, m \leq 100$;

For the first 20% of the data, $n, m \leq 5000$;

For another 10% of the data, $\mathrm{type} \leq 1$;

For another 20% of the data, $\mathrm{type} \leq 2$;

For another 15% of the data, $\mathrm{type} = 0$ or $3$;

For 100% of the data, $n \leq 10^5$, $m \leq 2 \times 10^5$, $0 \leq d_i \leq 10^4$, $0 \leq l_i \leq 10^9$. In the second type of test, $0 \leq x_0 \leq 10^9$, and in modification operations, $0 \leq x \leq 10^9$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.