Potential
Practice
4 (5 votes)
Data structures
Medium
Segment trees
Problem
82% Success 3829 Attempts 50 Points 4s Time Limit 512MB Memory 1024 KB Max Code

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
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

Code Editor

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
MediumSegment Trees
Points:50
10 votes
Tags:
ApprovedBinary SearchData StructuresMediumMerge sortOpenSegment Trees
Points:50
1 votes
Tags:
Medium
Editorial

Login to unlock the editorial