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 \(X_{pos} = x\)
- 2 \(pos\) p: set \(P_{pos} = p\)
- 3 a b: find \(max\{X_i + min(P_i, i - a) | i \in [a, b]\}\)
Input format
The first line of input contains two space separated integers n and q (\(1 \leq n, q \leq 3 \cdot 10^5\)) - size of arrays and number of queries.
The second line of input contains n space separated integers \(X_i\) (\(-10^9 \leq X_i \leq 10^9\)).
The third line of input contains n space separated integers \(P_i\) (\(-10^9 \leq P_i \leq 10^9\)).
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 (\(1 \leq pos \leq n\), \(-10^9 \leq x \leq 10^9\)) - parameters for first type query or
- 2 \(pos\) p (\(1 \leq pos \leq n\), \(-10^9 \leq p \leq 10^9\)) - parameters for second type query or
- 3 a b (\(1 \leq a \leq b \leq n\)) - parameters for third type query
Output format
For each third type query print the answer for it.
Submissions
Please login to view your submissions
Similar Problems
Points:50
12 votes
Tags:
Advanced Data StructuresData StructuresSegment Trees
Points:50
7 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresMediumOffline ProcessingSegment Trees
Points:50
7 votes
Tags:
Advanced Data StructuresData StructuresMediumRange querySegment Trees
Editorial