#P3332. [ZJOI2013] K大数查询

    ID: 2381 远端评测题 1500ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2013线段树浙江树套树整体二分

[ZJOI2013] K大数查询

Description

You need to maintain nn multisets of integers, numbered from 11 to nn.
All sets are initially empty. There are mm operations:

  • 1 l r c: Add cc to every set with index in [l,r][l,r].
  • 2 l r c: Query the cc-th largest number in the union of all sets with indices in [l,r][l,r].

Note that the union of multisets does not remove duplicates, e.g., {1,1,4}{5,1,4}={1,1,4,5,1,4}\{1,1,4\}\cup\{5,1,4\}=\{1,1,4,5,1,4\}.

Input Format

The first line contains two positive integers n,mn, m, the number of sets and the number of operations.
Each of the next mm lines contains four integers describing one operation.

Output Format

For each operation of type 2, output one line with a single integer, the answer.

2 5
1 1 2 1
1 1 2 2
2 1 1 2
2 1 1 1
2 1 2 3
1
2
1

Hint

[Sample Explanation]
The 1st operation adds one 11 to sets 11 and 22.
The 2nd operation adds one 22 to sets 11 and 22.
The 3rd operation queries the 2nd largest number in set 11, which is 11.
The 4th operation queries the 1st largest number in set 11, which is 22.
The 5th operation queries the 3rd largest number in the union {1,2,1,2}\{1,2,1,2\} of sets 11 and 22, which is 11.

Constraints
1n,m5×1041 \le n,m \le 5\times 10^4
1l,rn1 \le l,r \le n
In operation 1, cn|c| \le n
In operation 2, 1c<2631 \le c < 2^{63}, and the cc-th largest number exists.


upd 2023.8.23\text{upd 2023.8.23}:Added a new set of hack testdata.

Translated by ChatGPT 5