atcoder#ASAPORO2C. Paired Parentheses

Paired Parentheses

Score : 700700 points

Problem Statement

You are given two sequences aa and bb, both of length 2N2N. The ii-th elements in aa and bb are aia_i and bib_i, respectively. Using these sequences, Snuke is doing the job of calculating the beauty of pairs of balanced sequences of parentheses (defined below) of length 2N2N. The beauty of a pair (s,t)(s,t) is calculated as follows:

  • Let X=0X=0.
  • For each ii between 11 and 2N2N (inclusive), increment XX by aia_i if si=tis_i = t_i, and increment XX by bib_i otherwise.
  • The beauty of (s,t)(s,t) is the final value of XX.

You will be given QQ queries. Process them in order. In the ii-th query, update the value of apia_{p_i} to xix_i, and the value of bpib_{p_i} to yiy_i. Then, find the maximum possible beauty of a pair of balanced sequences of parentheses.

In this problem, only the sequences below are defined to be balanced sequences of parentheses.

  • An empty string
  • The concatenation of (, ss, ) in this order, where ss is a balanced sequence of parentheses
  • The concatenation of ss, tt in this order, where ss and tt are balanced sequences of parentheses

Constraints

  • 1N,Q1051 \leq N,Q \leq 10^{5}
  • 109ai,bi,xi,yi109-10^{9} \leq a_i,b_i,x_i,y_i \leq 10^{9}
  • 1pi2N1 \leq p_i \leq 2N
  • All input values are integers.

Partial Scores

  • In the test set worth 200200 points, N5N \leq 5 and Q10Q \leq 10.
  • In the test set worth 300300 points, Q=1Q = 1.

Input

Input is given from Standard Input in the following format:

NN QQ

a1a_1 a2a_2 ...... a2Na_{2N}

b1b_1 b2b_2 ...... b2Nb_{2N}

p1p_1 x1x_1 y1y_1

::

pQp_Q xQx_Q yQy_Q

Output

Print QQ lines. The ii-th line should contain the response to the ii-th query.

2 2
1 1 7 3
4 2 3 3
2 4 6
3 2 5
15
15
  • The first query updates aa and bb to a=(1,4,7,3),b=(4,6,3,3)a=(1,4,7,3),b=(4,6,3,3). The maximum possible beauty is 1515 for (s,t)=((s,t) =(()(),()())).
  • The second query updates aa and bb to a=(1,4,2,3),b=(4,6,5,3)a=(1,4,2,3),b=(4,6,5,3). The maximum possible beauty is 1515 for (s,t)=((s,t) =(()(),(()))).
7 7
34 -20 -27 42 44 29 9 11 20 44 27 19 -31 -29
46 -50 -11 20 28 46 12 13 33 -22 -48 -27 35 -17
7 27 34
12 -2 22
4 -50 -12
3 -32 15
8 -7 23
3 -30 11
4 -2 23
311
312
260
286
296
292
327