This page is still under construction.

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

Maximum Interval Sum 2

Time limit1sMemory limit256 MB

Summary
For a sequence with point updates, answer range queries for the maximum of U times a subarray sum plus V times its length minus one.
Level

Hard8 of 10

Topics
Segment tree, Divide and conquer, Dynamic programming, Math
Solved
No attempts yet

Problem

You are given an integer sequence K1,K2,…,KNK_1, K_2, \ldots, K_N of length NN and two constants UU and VV.

There are QQ queries of two kinds.

  1. Given AA and BB, find the maximum of U×(Ki+Ki+1+⋯+Kj)+V×(j−i)U \times (K_i + K_{i+1} + \cdots + K_j) + V \times (j - i) over all pairs (i,j)(i, j) with A≤i≤j≤BA \le i \le j \le B.
  2. Given AA and BB, set the value of KAK_A to BB.

Input

The first line contains the integers NN, QQ, UU, and VV. (1≤N,Q≤1051 \le N, Q \le 10^5, −5≤U,V≤5-5 \le U, V \le 5)

The second line contains the integers K1,K2,…,KNK_1, K_2, \ldots, K_N. (−100≤Ki≤100-100 \le K_i \le 100)

Each of the next QQ lines contains one query as three integers CC, AA, and BB. (0≤C≤10 \le C \le 1)

If CC is 0 the query is of the first kind, otherwise it is of the second kind. For a query of the first kind, 1≤A≤B≤N1 \le A \le B \le N. For a query of the second kind, 1≤A≤N1 \le A \le N and −100≤B≤100-100 \le B \le 100.

Output

For each query of the first kind, print its result on its own line, in the order the queries are given.

Examples1

  1. Example 1

    Input
    5 3 2 4
    1 1 1 1 1
    0 1 5
    1 3 -2
    0 1 5
    
    Expected output
    26
    20