luogu#P4848. 崂山白花蛇草水

崂山白花蛇草水

Problem Description

Ace (shenben, “神犇”) Aleph set a flag before SDOI Round 2: if he got into the provincial team, he would livestream himself drinking Laoshan Baihua Shecao Water. With his strength, Aleph easily made it into the Shandong provincial team, and now it is time for him to keep his promise. Rookie (juruo, “蒟蒻”) Bob specially prepared 999,999,999,999,999,999 bottles of Laoshan Baihua Shecao Water, hoping to force Ace Aleph to drink them. Ace Aleph begged (on his knees) rookie Bob not to do that. Since Ace Aleph is an ace, rookie Bob finally agreed, but Bob decided to play along and make Aleph answer some questions.

More specifically, rookie Bob will place some Laoshan Baihua Shecao Water on a spacious square (which can be seen as some integer grid points on a 2D plane), and then ask Ace Aleph: within the rectangular region x1xx2,y1yy2x_1\le x\le x_2,y_1\le y\le y_2, what is the kk-th largest bottle count. To avoid trouble, rookie Bob will not place Laoshan Baihua Shecao Water at the same position twice or more, but he still wants to make things difficult for Ace Aleph, hoping that Aleph can answer immediately for every query.

Ace Aleph does not care to solve such a problem, so he hands it to you.

Input Format

The first line contains two positive integers nn and qq, indicating the coordinate range on both axes and the number of operations by rookie Bob (including both placements and queries).

The next qq lines each describe one operation by rookie Bob, in the following format:
The first number is type\mathrm{type}, indicating the operation type. type=1\mathrm{type}=1 means a placement, and type=2\mathrm{type}=2 means a query.
If type=1\mathrm{type}=1, it is followed by three positive integers x,y,vx, y, v, meaning that vv bottles of Laoshan Baihua Shecao Water are placed at the integer point (x,y)(x, y).
If type=2\mathrm{type}=2, it is followed by five positive integers x1,y1,x2,y2,kx_1, y_1, x_2, y_2, k, meaning a query in the rectangular region x1xx2,y1yy2x_1\le x\le x_2,y_1\le y\le y_2: what is the kk-th largest bottle count.

To reflect the online nature of the program, you must XOR every value you read (except the type\mathrm{type} value) with lastans\mathrm{lastans}, where lastans\mathrm{lastans} is the answer to the previous query. If the previous query answer is NAIVE!ORZzyz. (see the sample output), then set lastans\mathrm{lastans} to 00. Initially, lastans\mathrm{lastans} is 00. Initially, there is no Laoshan Baihua Shecao Water on the plane.

Output Format

For each operation with type=2\mathrm{type}=2, output one line: the kk-th largest bottle count. If the kk-th largest bottle count does not exist, output NAIVE!ORZzyz..

10 7
1 1 1 1
1 2 2 3
1 4 1 2
1 3 4 4
2 1 1 4 1 3
2 2 2 3 5 4
2 2 1 4 4 2
NAIVE!ORZzyz.
NAIVE!ORZzyz.
3

Hint

Constraints: For all testdata, n500000n\le500000, q100000q\le100000, 1x,yn1\le x, y\le n, 1v1091\le v\le 10^9, 1x1x2n1\le x_1\le x_2\le n, 1y1y2n1\le y_1\le y_2\le n, 1kq1\le k\le q.

Translated by ChatGPT 5