#P11244. 吻秋

    ID: 9925 远端评测题 900ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟暴力数据结构洛谷原创O2优化枚举排序洛谷月赛

吻秋

Background

English statement. You must submit your code at the Chinese version of the statement.

After the autumn rain has just kissed the earth, white clouds roll up red, orange, yellow, green, cyan, blue, and purple.

Wavelengths within the visible light range fall freely, giving the rising water vapor a gradually changing rhythm.

The blurry impression of gradients is always hurried past by sunny days, but the often unusual range makes us remember it more clearly.

So, is being ordered really optimal?

Problem Description

Xiao C has mm integer sequences a1ama_1 \dots a_m, and each sequence has length nn.

Xiao C wants to sort his sequences by integer value. So Xiao C has qq operations. In each operation:

  • Either, Xiao C gives x,y (xy)x, y\ (x \neq y). He wants to concatenate axa_x and aya_y into a sequence bb of length 2n2n. After sorting bb in nondecreasing order, take b1bnb_1 \dots b_n as the new axa_x, and take bn+1b2nb_{n+1} \dots b_{2n} as the new aya_y.
  • Or, Xiao C gives i,ji, j. Careful Xiao C wants to ask you: after the previous operations, what is the value of ai,ja_{i,j}? You need to answer his question exactly.

Input Format

The first line contains three integers n,m,qn, m, q.

The next mm lines each contain nn integers. The jj-th integer on the ii-th line denotes ai,ja_{i,j}.

The next qq lines each contain three integers, describing one operation or one query, in one of the following two formats:

  • 1 x y\verb!1 x y! means sorting axa_x and aya_y, where 1xym1 \leq x \neq y \leq m.
  • 2 i j\verb!2 i j! means querying ai,ja_{i,j}, where 1im1 \leq i \leq m and 1jn1 \leq j \leq n.

Output Format

For each query, output one integer per line, representing the answer.

5 3 6
1 3 2 5 6
2 7 8 2 2
3 5 3 4 8
2 1 5
1 1 2
2 2 4
1 1 3
1 2 1
2 2 3
6
7
2

6 5 20
5 14 13 1 15 17
7 7 19 3 8 6
16 13 13 6 14 2
12 5 4 17 12 3
19 19 4 6 3 3
2 5 3
1 4 3
2 1 1
1 2 5
2 4 6
2 2 2
1 4 2
1 2 4
2 1 1
2 3 3
2 3 3
1 4 2
1 4 1
2 3 5
1 3 4
1 4 1
1 1 4
1 5 1
2 2 4
2 4 2

4
5
12
3
5
13
13
16
6
14

Hint

Constraints

This problem uses bundled test and subtask dependencies.

Because the maximum input sizes of the last two subtasks reach 18MB18\text{MB} and more than 50MB50\text{MB} respectively, C++ users may choose to use the following fast I/O template:

namespace FastIO {
	char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p1 = buf, p2 = (p1 + fread(buf, 1, 1 << 21, stdin))) == p1 ? EOF : *p1++)
	template <typename T> inline T read() { T x = 0, w = 0; char ch = getchar(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar(); return w ? -x : x; }
	template <typename T> inline void write(T x) { if (!x) return; write<T>(x / 10), putchar((x % 10) ^ '0'); }
	template <typename T> inline void print(T x) { if (x > 0) write<T>(x); else if (x < 0) putchar('-'), write<T>(-x); else putchar('0'); }
	template <typename T> inline void print(T x, char en) { print<T>(x), putchar(en); }
}; using namespace FastIO;
#undef getchar()

It is not guaranteed that languages other than C++ can pass, but sufficient time limits are guaranteed for C++.


  • Subtask 0 (0 pts): samples.
  • Subtask 1 (9 pts): n104n \leq 10^4, q3000q \leq 3000. Depends on Subtask 00.
  • Subtask 2 (23 pts): q3000q \leq 3000. Depends on Subtasks 0,10, 1.
  • Subtask 3 (20 pts): m5m \leq 5, q4×105q \leq 4\times 10^5. Depends on Subtask 00.
  • Subtask 4 (28 pts): q4×105q \leq 4\times 10^5. Depends on Subtasks 030 \sim 3.
  • Subtask 5 (20 pts): no special constraints. Depends on Subtasks 040 \sim 4.

For all testdata, 1nm2×1061 \leq n \cdot m \leq 2\times 10^6, 1m201 \leq m \leq 20, 1q5×1061 \leq q \leq 5\times 10^6, and 1ai,j1071 \leq a_{i,j} \leq 10^7. For each operation or query, 1xym1 \leq x \neq y \leq m, 1im1 \leq i \leq m, and 1jn1 \leq j \leq n.

Translated by ChatGPT 5