Potential

4

5 votes
Data Structures, Medium, Segment Trees
Problem

Sometimes long stories are very boring. So we decided to make statement as short as possible!

You have two integer arrays of size n: X and P. Your task is to perform q queries. There are three types of queries:

  • 1 pos x: set Xpos=x
  • 2 pos p: set Ppos=p
  • 3 a b: find max{Xi+min(Pi,ia)|i[a,b]}

Input format

The first line of input contains two space separated integers n and q (1n,q3105) - size of arrays and number of queries.

The second line of input contains n space separated integers Xi (109Xi109).

The third line of input contains n space separated integers Pi (109Pi109).

Then q lines follow. The i-th of them contains parameters of the i-th query.

The i-th line can be:

  • 1 pos x (1posn, 109x109) - parameters for first type query or
  • 2 pos p (1posn, 109p109) - parameters for second type query or
  • 3 a b (1abn) - parameters for third type query

Output format

For each third type query print the answer for it.

Sample Input
3 4
1 3 0
2 -1 10
3 1 3
1 3 1
2 2 5
3 1 3
Sample Output
2
4
Time Limit: 4
Memory Limit: 512
Source Limit:
Explanation

max{1+min(0,2),3+min(1,1),0+min(10,2)}=2

max{1+min(0,2),3+min(5,1),1+min(10,2)}=4

Editor Image

?