Problem list
Log in
#coci00714 · COCI 2025/2026 Contest 4

Magija

Platinum III 1.0 s 32 MB

"Welcome to the SHOW! You are about to witness a spectacular magic performance by Magic Ivor." This is how Ivor imagines the announcement of his first magic performance, but first he needs to prepare. Ivor will request $n$ volunteers for his tricks and arrange them on the stage. At the left end of the line is person 1, to the right of person 1 is person 2, to the right of person 2 is person 3, and so on. The tricks that Ivor learns during his preparation can be described in the form $l$ $r$ len. In such a trick, Ivor learns to swap the positions of people, specifically to swap two disjoint intervals of equal length: the interval [l, $l + len - 1$] and the interval [r, $r + len - 1$]. Two intervals are disjoint if they do not have any common volunteers. Often, Ivor wonders, for a given person $x$, what are the minimum and maximum positions that this person can occupy if he can use his learned tricks in any order and any ammount of times. He also does not have to use all the tricks he has learned so far. There are $Q$ events describing Ivor’s preparation, and we distinguish between two types of events.

  • An event of the form 1 $x$ asks you to answer Ivor’s question considering the tricks he has learned so far. He may use the tricks in any order and does not have to use all of them.
  • An event of the form 2 $l$ $r$ len indicates a trick that Ivor has just learned. Your task is to help Ivor and answer all events of the first type.

Input

The first line contains the natural numbers $n$ and $q$ ($1 \le n$, $q \le 2 \cdot 10^{5}$), as described in the problem text. Each of the following $Q$ lines describes one event of one of the following forms:

  • 1 $x$ – Ivor wants to know the minimum and maximum positions that person $x$ can occupy ($1 \le x \le n$).
  • 2 $l$ $r$ len – Ivor has learned to swap the intervals [l, $l + len - 1$] and [r, $r + len - 1$]. It holds that $1 \le len \le n$, $l + len - 1 < r$, and $r + len - 1 \le n$.

Output

After each event of type 1, print two numbers: the minimum and maximum positions that the given person can occupy, separated by a space.

Example 1

Input
5 3
2 3 4 1
1 5
1 3
Output
5 5
3 4

Example 2

Input
9 2
2 1 7 2
1 2
Output
2 8
Source
COCI 2025/2026 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code