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.
Hard8Segment treeBinary searchSortingCombinatoricsNo attempts yetTime limit2sMemory limit128 MBSnow 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 Lmm and Rmm in A, B, C, ..., X and K regions in total.
An administrative reform split the country into N regions, and reading out K region names one by one became too much work. So Taekhee decided to report only the count K of regions whose snow depth is between Lmm and Rmm. That number alone says nothing about any single region, so Taekhee also reports the depth of the region with the T-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.
Operation 4 counts equal depths separately. For example, if five regions hold (3,1,2,1,2), then for T 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.
The first line contains the number of regions N and the number of commands M. (1≤N,M≤105)
The second line contains the current snow depths S1,S2,…,SN. (0≤Si≤109)
Each of the next M lines contains one command in one of the following four forms.
1 i x: region i gains xmm of snow. (1≤i≤N, 1≤x≤109)2 i y: region i loses ymm of snow. (1≤i≤N, 1≤y≤109)3 L R: count the regions whose snow depth is at least Lmm and at most Rmm. (0≤L≤R≤1018)4 T: report the snow depth of the region with the T-th deepest snow. (1≤T≤N)No command of type 2 ever makes a snow depth negative.
For each command of type 3 and each command of type 4, print the answer as one integer on its own line.