#abc368g. G - Add and Multiply Queries

G - Add and Multiply Queries

Score : 575575 points

问题陈述

你得到了两个正整数序列 AABB,它们的长度都是 NN。按照给定的顺序处理 QQ 个查询,每个查询的形式如下。每个查询是以下三种类型之一。

  • 类型 11:以 1 i x 的形式给出。将 AiA_i 替换为 xx
  • 类型 22:以 2 i x 的形式给出。将 BiB_i 替换为 xx
  • 类型 33:以 3 l r 的形式给出。解决以下问题并打印答案。
    • 最初,设置 v=0v = 0。按照这个顺序,对于 i=l,l+1,...,ri = l, l+1, ..., r,将 vv 替换为 v+Aiv + A_iv×Biv \times B_i。找到最终可能的最大 vv 值。

保证给定类型 33 查询的答案最多为 101810^{18}

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given sequences of positive integers AA and BB of length NN. Process QQ queries given in the following forms in the order they are given. Each query is of one of the following three types.

  • Type 11: Given in the form 1 i x. Replace AiA_i with xx.
  • Type 22: Given in the form 2 i x. Replace BiB_i with xx.
  • Type 33: Given in the form 3 l r. Solve the following problem and print the answer.
    • Initially, set v=0v = 0. For i=l,l+1,...,ri = l, l+1, ..., r in this order, replace vv with either v+Aiv + A_i or v×Biv \times B_i. Find the maximum possible value of vv at the end.

It is guaranteed that the answers to the given type 33 queries are at most 101810^{18}.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9
  • 1Q1051 \leq Q \leq 10^5
  • For type 11 and 22 queries, 1iN1 \leq i \leq N.
  • For type 11 and 22 queries, 1x1091 \leq x \leq 10^9.
  • For type 33 queries, 1lrN1 \leq l \leq r \leq N.
  • For type 33 queries, the value to be printed is at most 101810^{18}.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

B1B_1 B2B_2 \cdots BNB_N

QQ

query1query_1

query2query_2

\vdots

queryQquery_Q

Here, queryiquery_i is the ii-th query, given in one of the following formats:

11 ii xx

22 ii xx

33 ll rr

Output

Let qq be the number of type 33 queries. Print qq lines. The ii-th line should contain the answer to the ii-th type 33 query.

Sample Input 1

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

Sample Output 1

12
7

For the first query, the answer is ((0+A1)×B2)×B3=12((0 + A_1) \times B_2) \times B_3 = 12. For the third query, the answer is ((0+A1)+A2)+A3=7((0 + A_1) + A_2) + A_3 = 7.

Sample Input 2

6
65 32 12 5 8 312
4 1 3 15 16 2
6
3 2 6
3 1 5
1 5 6
2 4 9
3 2 6
3 3 5

Sample Output 2

46080
69840
27648
1728