Center Stage
InterviewTime limit2sMemory limit512 MB
Given an array with point updates, find for each range query the maximum of A_b - A_a - A_c over indices a < b < c inside the range.
- Level
Medium6 of 10
- Topics
- Segment tree, Array
- Solved
- No attempts yet
Problem
Jeonghu, a member of Nacoder's 39th class, wants to present a Nacoder stage at Solde Festival 2022. The stage is titled 'Sequence and Query 333'. Students numbered 1 to stand in a line and perform actions designed by Jeonghu. Each action is one of two types. Each student has a charm represented by one integer.
- A type 1 action changes the charm of student to .
- A type 2 action sends three different students from to onto the stage. For , students , , and perform the action.
The more outstanding the center's charm is, the higher the stage charm becomes. Let be the charm of student . The stage charm is computed as .
For each action, pick three students to help Jeonghu reach the maximum stage charm.
Input
The first line contains two integers and , separated by a space. The second line contains integers separated by spaces. The -th number is the charm of student . From the third line to line , each line contains three integers separated by spaces. The first number in each line is the action type. For a type 1 action, and follow. For a type 2 action, and follow.
Output
For each type 2 action, print the maximum stage charm on its own line.
Constraints
- All given numbers are integers.
- At least one type 2 action is given.