#P15352. [COCI 2025/2026 #4] 魔术 / Magija

    ID: 17316 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>倍增并查集COCI(克罗地亚)2026

[COCI 2025/2026 #4] 魔术 / Magija

Background

Please note that this problem has an unusual memory limit.

Problem Description

Consider a permutation p1∼pNp_1 \sim p_N of 1∼N1 \sim N. Define an operation (l,r,len)(l, r, \mathrm{len}) as follows:

  • For i=0,…,len−1i = 0, \ldots, \mathrm{len} - 1, swap pl+ip_{l+i} and pr+ip_{r+i}.

It is guaranteed that [l,l+len−1][l, l+\mathrm{len}-1] and [r,r+len−1][r, r+\mathrm{len}-1] do not overlap.

There is an operation pool, initially empty.

There are QQ events:

  • 1\texttt{1} xx: Starting from the permutation [1,2,…,N][1,2,\ldots,N], perform any number of operations from the operation pool (possibly zero times), and find the minimum and maximum possible final index of xx after all operations are done.
    • An operation can be used multiple times.
    • The order of operations does not matter.
    • You do not have to use all operations in the pool.
  • 2\texttt{2} ll rr len\mathrm{len}: Add an operation (l,r,len)(l, r, \mathrm{len}) to the operation pool.

Answer each query.

Input Format

The first line contains two positive integers N,QN, Q (1≤N,Q≤2×1051 \le N, Q \le 2 \times 10^5).

The next QQ lines each contain two (or four) positive integers, in the form 1\texttt{1} xx or 2\texttt{2} ll rr len\mathrm{len}, describing an event. Where:

  • 1≤x≤N1 \le x \le N;
  • 1≤len≤N1 \le \mathrm{len} \le N, l+len−1<rl+\mathrm{len}-1 \lt r, r+len−1≤Nr+\mathrm{len}-1 \le N.

Output Format

For each event 1\texttt{1}, output one line with two positive integers, representing the minimum and maximum possible final index, respectively.

5 3
2 3 4 1
1 5
1 3
5 5
3 4
9 2
2 1 7 2
1 2
2 8

Hint

Sample Explanation

Explanation for sample 2: doing no operations gives the minimum value; performing the operation once gives the maximum value.

Subtasks

Subtask ID Score Constraints
11 99 N,Q≤5N, Q \le 5
22 1414 N,Q≤15N, Q \le 15
33 2222 N,Q≤5000N, Q \le 5000
44 1111 N≤4000N \le 4000
55 1717 N≤10000N \le 10000
66 3737 No additional constraints.

Translated by ChatGPT 5