Figurines

View as PDF

Submit solution


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

Author:
Problem type

Riolku has N friends, labelled from 1 to N. Him and his N friends recently got into collecting figurines! However, since their parents don't want them to waste 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 A_i and the trade figurines have values B_i.

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

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 l and r, he will replace their prized figurine with one of value k. Formally, for all i such that l \le i \le r, set A_i = k.
  2. Riolku feels remorse and offers his friends some new figurines. For each friend with label between l and r, he will offer a figurine of value k with which to replace their trade figurine. Formally, for all i such that l \le i \le r, set B_i = \max(B_i, k).
  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 l and r. Formally, find \max_{i=l}^r (A_i + B_i).

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

Constraints

  • 1 \le N \le 10^6
  • 1 \le Q \le 10^5
  • 1 \le l \le r \le N
  • |A_i|, |B_i|, |k| \le 10^9

Input Specification

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

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

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

Then Q 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 3, 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

Comments

There are no comments at the moment.