This page is still under construction.

Parts of this page are still being built. What you see may change.

Center Stage

Interview

Time limit2sMemory limit512 MB

Summary
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 NN stand in a line and perform QQ 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 xix_i to yiy_i.
  • A type 2 action sends three different students from lil_i to rir_i onto the stage. For li≤a<b<c≤ril_i \le a < b < c \le r_i, students aa, bb, and cc perform the action.

The more outstanding the center's charm is, the higher the stage charm becomes. Let AiA_i be the charm of student ii. The stage charm is computed as Ab−Aa−AcA_b - A_a - A_c.

For each action, pick three students to help Jeonghu reach the maximum stage charm.

Input

The first line contains two integers NN and QQ, separated by a space. The second line contains NN integers separated by spaces. The ii-th number is the charm AiA_i of student ii. From the third line to line Q+2Q + 2, each line contains three integers separated by spaces. The first number in each line is the action type. For a type 1 action, xix_i and yiy_i follow. For a type 2 action, lil_i and rir_i follow.

Output

For each type 2 action, print the maximum stage charm on its own line.

Constraints

  • 3≤N≤333,3333 \le N \le 333{,}333
  • 1≤Q≤333,3331 \le Q \le 333{,}333
  • 1≤xi≤N1 \le x_i \le N
  • −33,333,333≤Ai,yi≤33,333,333-33{,}333{,}333 \le A_i, y_i \le 33{,}333{,}333
  • 1≤li,ri≤N1 \le l_i, r_i \le N
  • li+2≤ril_i + 2 \le r_i
  • All given numbers are integers.
  • At least one type 2 action is given.

Examples1

  1. Example 1

    Input
    7 3
    5 -3 2 -9 5 3 -16
    2 1 6
    1 3 4
    2 3 5
    
    Expected output
    14
    -18