Figurines

View as PDF

Points: 20
Time limit: 1.0s
Java 2.0s
Memory limit: 256M
Java 512M

Author:
Problem type

Riolku has friends, labelled from to . Him and his friends recently got into collecting figurines! However, since their parents don't want them wasting all their money, they can only have two figurines at a time.

Each friend has one figurine that they consider "prized", and would never willingly give away, whereas they have another that they could trade, which we will call their "trade" figurine.

Being figurine connoisseurs, Riolku and his friends know that each figurine has a specific value. Initially, the prized figurines have values and the trade figurines have values .

Sometimes, Riolku gets greedy and steals some of his friend's prized figurines, replacing them with look alikes all with value . However, sometimes he feels remorseful and instead offers his friends new figurines. He offers some of his friends a figurine with value . If this value is larger than their trade figurine, they will replace their trade figurine with the figurine of value .

Occasionally he wonders who has the most valuable pair of figurines. The value of a pair is the value of their prized figurine plus the value of their trade figurine.

Riolku will only do 3 actions. The action specifics are below:

1. Riolku steals some of his friend's prized figurines. For each friend with label between and , he will replace their prized figurine with one of value . Formally, for all such that , set .
2. Riolku feels remorse and offers his friend's some new figurines. For each friend with label between and , he will offer a figurine of value with which to replace their trade figurine. Formally, for all such that , set .
3. Riolku wonders who has the best figurine pair. He wants to know the value of the best figurine pair for all friends with labels between and . Formally, find .

Riolku will perform actions. Can you answer his questions for him?

Input Specification

The first line contains two space-separated integers, and .

The next line contains integers, the elements of in order from to .

The next line contains integers, the elements of in order from to .

Then lines follow. Each is an operation of one of the following three forms:

• 1 l r k
• 2 l r k
• 3 l r

The first integer indicates the operation to be performed, corresponding with the task description.

Output Specification

For each operation of type , output the answer on its own line.

Sample Input

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

Sample Output

12
8
11
11