#P7706. 「Wdsr-2.7」文文的摄影布置

「Wdsr-2.7」文文的摄影布置

Description

Although there are many pictures, luckily, Wenwen has already arranged them into a line, numbered from left to right as 1n1 \sim n. The three pictures Wenwen chooses should form a subsequence of length 3\bf 3. (Let the chosen photo indices be i,j,ki, j, k, then it must satisfy i<j<ki < j < k.)

In addition, Wenwen assigns each photo an attractiveness AiA_i and a size BiB_i.

Because an overly large newspaper layout will reduce readers' interest, after choosing two photos i,ki, k, it is required that the smallest BjB_j must be chosen.

Formally, define ψ(i,k)=Ai+Akmin(Bj)\psi(i,k) = A_i + A_k - \min(B_j), where it needs to satisfy i<j<ki < j < k.

After figuring out how to compute the value of the photos, Wenwen will give you a total of mm operations, which can be divided into the following three types:

  • 1 x y\colorbox{f0f0f0}{\verb!1 x y!}: The attractiveness of a photo changes. Wenwen modifies AxA_x to yy.

  • 2 x y\colorbox{f0f0f0}{\verb!2 x y!}: The size of a photo changes. Wenwen modifies BxB_x to yy.

  • 3 l r\colorbox{f0f0f0}{\verb!3 l r!}: Wenwen plans to use the pictures from the ll-th to the rr-th in the material library. You need to tell her the maximum value of ψ(x,y)\psi(x,y) ( lxx+1<yrl \le x \le x+1 < y \le r ).

Input Format

The first line contains two integers n,mn, m, representing the number of photos and the number of operations.

The second line contains nn integers, representing the sequence AA, describing the attractiveness of each photo.

The third line contains nn integers, representing the sequence BB, describing the size of each photo.

The next mm lines each describe an operation, in the format described above.

Output Format

For each type 3 operation, output one line with one integer, representing the answer.

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

Hint

Constraints and conventions

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|}\hline \textbf{Subtask} & \bm{n,m} & \textbf{Special property} & \textbf{Score}\cr\hline 1 & 1\le n,m\le 300 & \text{None} & 10\cr\hline 2 & 1\le n,m\le 5\times 10^3 & \text{None} & 20\cr\hline 3 & 1\le n,m\le 5\times 10^5 & \text{Only operation 3} & 20\cr\hline 4 & 1\le n,m\le 10^5 & \text{None} & 20\cr\hline 5 & \text{No special restrictions} & \text{None} & 30\cr\hline \end{array}$$
  • For 100%100\% of the testdata:

    1n,m5×1051 \le n,m \le 5 \times 10^5.

    1Ai,Bi,y1081 \leq A_i,B_i,y \leq 10^8, 1xn1 \le x \le n, 1lrn1 \le l \le r \le n.

    It is guaranteed that rl+13r-l+1 \geq 3, i.e., the length of the queried interval is at least 33.

Translated by ChatGPT 5