Under construction

Still being built. Things may change

Maximum range sum? 1

Interview

Time limit1sMemory limit128 MB

Summary
Maintain an array under point updates. For each range query, find the maximum of U times a subarray sum plus V times its length over all subarrays inside the range.
Level

Medium5 of 10

Topics
Array, Brute force, Prefix sum, Implementation
Solved
No attempts yet

Problem

You are given a sequence K1,K2,…,KNK_1, K_2, \dots, 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 value of U×(Ki+Ki+1+⋯+Kj)+V×(j−i)U \times (K_i + K_{i+1} + \dots + K_j) + V \times (j - i) over all ii, jj 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≤1031 \le N, Q \le 10^3, −5≤U,V≤5-5 \le U, V \le 5)

The second line contains the integers K1,K2,…,KNK_1, K_2, \dots, K_N. (−102≤Ki≤102-10^2 \le K_i \le 10^2)

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 and 1≤A≤B≤N1 \le A \le B \le N. If CC is 1, the query is of the second kind and 1≤A≤N1 \le A \le N, −102≤B≤102-10^2 \le B \le 10^2.

Output

For each query of the first kind, print its result on its own line.

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