Under construction

Still being built. Things may change

Weather Forecast

Time limit2sMemory limit128 MB

Summary
Maintain N snow depths under point increments and decrements, then answer range-count queries (depth between L and R) and T-th largest value queries online.
Level

Hard8 of 10

Topics
Segment tree, Binary search, Sorting, Combinatorics
Solved
No attempts yet

Problem

Snow falls all day long in Snowflake Country. It keeps piling up, and it keeps melting.

Taekhee, the weather caster of Snowflake Country, talks about nothing but snow. Earthquake or typhoon, the forecast always has the same shape.

Snow now measures between LLmm and RRmm in A, B, C, ..., X and KK regions in total.

An administrative reform split the country into NN regions, and reading out KK region names one by one became too much work. So Taekhee decided to report only the count KK of regions whose snow depth is between LLmm and RRmm. That number alone says nothing about any single region, so Taekhee also reports the depth of the region with the TT-th deepest snow. With so many regions, doing this by hand is hopeless. Taekhee wants a program that tracks the snow depths automatically.

The program handles four operations.

  1. Region ii gains xxmm of snow.
  2. Region ii loses yymm of snow to melting.
  3. Count the regions whose snow depth is at least LLmm and at most RRmm.
  4. Report the snow depth of the region with the TT-th deepest snow.

Operation 4 counts equal depths separately. For example, if five regions hold (3,1,2,1,2)(3, 1, 2, 1, 2), then for TT equal to 1, 2, 3, 4, 5 the answers are 3, 2, 2, 1, 1 in that order.

A forecast has to be fast, so the program has to be fast. Write it for Taekhee.

Input

The first line contains the number of regions NN and the number of commands MM. (1≤N,M≤1051 \le N, M \le 10^5)

The second line contains the current snow depths S1,S2,…,SNS_1, S_2, \dots, S_N. (0≤Si≤1090 \le S_i \le 10^9)

Each of the next MM lines contains one command in one of the following four forms.

  • 1 i x: region ii gains xxmm of snow. (1≤i≤N1 \le i \le N, 1≤x≤1091 \le x \le 10^9)
  • 2 i y: region ii loses yymm of snow. (1≤i≤N1 \le i \le N, 1≤y≤1091 \le y \le 10^9)
  • 3 L R: count the regions whose snow depth is at least LLmm and at most RRmm. (0≤L≤R≤10180 \le L \le R \le 10^{18})
  • 4 T: report the snow depth of the region with the TT-th deepest snow. (1≤T≤N1 \le T \le N)

No command of type 2 ever makes a snow depth negative.

Output

For each command of type 3 and each command of type 4, print the answer as one integer on its own line.

Examples5

  1. Example 1

    Input
    5 7
    0 0 1 0 0
    1 2 2
    3 1 2
    1 5 5
    3 2 5
    4 3
    2 5 5
    3 2 5
    
    Expected output
    2
    2
    1
    1
    
  2. Example 2

    Input
    5 5
    3 1 2 1 2
    4 1
    4 2
    4 3
    4 4
    4 5
    
    Expected output
    3
    2
    2
    1
    1
    
  3. Example 3

    Input
    1 4
    0
    4 1
    3 0 0
    1 1 1000000000
    4 1
    
    Expected output
    0
    1
    1000000000
    
  4. Example 4

    Input
    6 9
    5 5 5 5 5 5
    3 5 5
    3 0 4
    3 6 1000000000000000000
    4 1
    4 6
    2 3 5
    3 5 5
    4 6
    3 0 0
    
    Expected output
    6
    0
    0
    5
    5
    5
    0
    1
    
  5. Example 5

    Input
    3 9
    1000000000 1000000000 1000000000
    1 1 1000000000
    1 1 1000000000
    1 1 1000000000
    1 1 1000000000
    1 1 1000000000
    4 1
    3 0 1000000000000000000
    3 1000000001 1000000000000000000
    4 3
    
    Expected output
    6000000000
    3
    1
    1000000000