Mizuyokan 2

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

Mizuyokan is a Japanese confectionery made of azuki beans paste. It was made by cooking azuki beans paste with agar, and solidifying them in a rectangular-shaped form.

Now, JOI-kun has a mizuyokan machine. Using it, JOI-kun can make a horizontally long rectangular-shaped mizuyokan with N1N - 1 vertical cutlines. The length of the mizuyokan and the positions of the cutlines are determined by the NN parameters d_1,d_2,,d_Nd\_1, d\_2, \dots , d\_N set on the machine. The length of the mizuyokan is d_1+d_2++d_Nd\_1 + d\_2 + \cdots + d\_N. The distance between the (i1)(i - 1)-th cutline (1iN1 ≤ i ≤ N) from the left and the ii-th cutline from the left is d_id\_i. Here, we consider the leftmost edge of the mizuyokan as the 00-th cutline, and the rightmost edge of the mizuyokan as the NN-th cutline. In the beginning, the parameters of the mizuyokan machine satisfy d_i=L_id\_i = L\_i (1iN1 ≤ i ≤ N).

JOI-kun has a plan to organize QQ tea parties. The jj-th tea party (1jQ1 ≤ j ≤ Q) is described by the integers X_jX\_j, Y_jY\_j, A_jA\_j, B_jB\_j. It proceeds as follows.

  1. The parameter d_X_jd\_{X\_j} of the mizuyokan machine is updated, and it is set as Y_jY\_j.
  2. JOI-kun makes a new mizuyokan using the mizuyokan machine. He takes the part of the mizuyokan between the A_jA\_j-th cutline and the B_jB\_j-th cutline, and uses it for the tea party. He eats the rest.
  3. JOI-kun cuts the part of the mizuyokan for the tea party along some of the cutlines. He cuts the part of the mizuyokan into one or more pieces. In this process, the following condition should be satisfied: if the pieces are ordered from the left as in the original positions, the sequence of the lengths of the pieces is zigzag.

Here, a sequence is called zigzag if the elements of the sequence increase and decrease alternately. For example, the sequences (2,9,2,7)(2, 9, 2, 7), (7,1,9,4,6)(7, 1, 9, 4, 6), (5)(5), (2,1)(2, 1) are zigzag, but the sequences (1,2,3)(1, 2, 3), (7,1,4,4,6)(7, 1, 4, 4, 6), (2,2)(2, 2) are not zigzag. Precisely, a sequence (x_1,x_2,,x_m)(x\_1, x\_2, \dots , x\_m) is called zigzag if one (or the both) of the following conditions are satisfied:

  • For k=1,2,,m1k = 1, 2, \dots , m - 1, the inequality x_k<x_k+1x\_k < x\_{k+1} is satisfied if kk is odd, and the inequality x_k>x_k+1x\_k > x\_{k+1} is satisfied if kk is even.
  • For k=1,2,,m1k = 1, 2, \dots , m - 1, the inequality x_k>x_k+1x\_k > x\_{k+1} is satisfied if kk is odd, and the inequality x_k<x_k+1x\_k < x\_{k+1} is satisfied if kk is even.

Since JOI-kun wants to give mizuyokan to as many friends as possible, he wants to maximize the number of pieces obtained by the procedure 3. of the tea party.

Write a program which, given information of the initial parameters of the mizuyokan machine and the plan of the tea parties, calculates, for each tea party, the maximum possible number of pieces obtained by cutting the part of the mizuyokan so that the condition is satisfied. Note that, under the constraints of this task, it is always possible to cut the part of the mizuyokan so that the condition is satisfied.

입력

Read the following data from the standard input.

NN

L_1L\_1 L_2L\_2 \cdots L_NL\_N

QQ

X_1X\_1 Y_1Y\_1 A_1A\_1 B_1B\_1

X_2X\_2 Y_2Y\_2 A_2A\_2 B_2B\_2

\vdots

X_QX\_Q Y_QY\_Q A_QA\_Q B_QB\_Q

출력

Write QQ lines to the standard output. The jj-th line (1jQ1 ≤ j ≤ Q) of output corresponds to the jj-th tea party. It contains the maximum possible number of pieces obtained by cutting the part of the mizuyokan in the jj-th tea party so that the condition is satisfied.

제한

  • 1N250,0001 ≤ N ≤ 250\\,000.
  • 1L_i1091 ≤ L\_i ≤ 10^9 (1iN1 ≤ i ≤ N).
  • 1Q50,0001 ≤ Q ≤ 50\\,000.
  • 1X_jN1 ≤ X\_j ≤ N (1jQ1 ≤ j ≤ Q).
  • 1Y_j1091 ≤ Y\_j ≤ 10^9 (1jQ1 ≤ j ≤ Q).
  • 0A_j<B_jN0 ≤ A\_j < B\_j ≤ N (1jQ1 ≤ j ≤ Q).
  • Given values are all integers.