QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#21403. 文艺平衡树

统计

This is a template problem.

You need to implement a data structure (you may refer to the problem title) to maintain a sequence and support the following operation:

Reverse a range. For example, if the original sequence is 5 4 3 2 1 and the range to reverse is $[2, 4]$, the result is 5 2 3 4 1.

Input

The first line contains $n$ and $m$, where $n$ is the number of elements in the initial sequence $\{ 1, 2, \ldots, n - 1, n \}$, and $m$ is the number of reversal operations.

The next $m$ lines each contain two numbers $[l, r]$, where it is guaranteed that $1 \leq l \leq r \leq n$.

Output

Output a single line containing $n$ numbers, representing the sequence after $m$ operations.

Examples

Input 1

5 3
1 3
1 3
1 4

Output 1

4 3 2 1 5

Constraints

$1 \leq n, m \leq 10^5$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.