#FT0000208. Truy vấn cộng và nhân (Add and Multiply Queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn cộng và nhân (Add and Multiply Queries)
Add and Multiply Queries
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given two arrays of positive integers and , both indexed from , process operations in order:
1 i x: replace with .2 i x: replace with .3 l r: start with . Process the indices in order. At each index choose exactly one update: or . Print the largest possible final value after processing index .
Type 3 queries do not modify either array, and the choices made within one query do not persist into other queries.
Input
- The first line contains .
- The second line contains integers .
- The third line contains integers .
- The fourth line contains .
- Each of the next lines is one of
1 i x,2 i x, or3 l r, as defined in the statement.
Output
For each type 3 operation, print one line containing its maximum attainable value, in query order.
Subtasks
-
Subtask 1 (20 points): ; ; types
1,2: , ; type3: ; every type3answer is at most . -
Subtask 2 (30 points): ; ; types
1,2: , ; type3: ; every type3answer is at most . -
Subtask 3 (50 points): ; ; types
1,2: , ; type3: ; every type3answer is at most .
Examples
Input
3
3 2 4
1 2 2
3
3 1 3
1 1 1
3 1 3
Output
12
7
Explanation
Initially and . For the first query 3 1 3, choose addition at index to obtain , then multiplication by at index to obtain , and multiplication by at index to obtain . These choices maximize the result. The update 1 1 1 changes to . In the last query, additions at all three positions yield , then , then ; multiplication at position would yield and at position would yield , both smaller. Thus the output lines are 12 and 7.