Cut and Paste
Time limit1sMemory limit128 MB
Simulate K cut-and-paste block moves on an N-line document and report the first ten resulting line values.
- Level
Medium5 of 10
- Topics
- Simulation, Array, Implementation
- Solved
- No attempts yet
Problem
A document produced by a text editor consists of lines. Initially the first line contains the number , the second line contains the number , and so on, so that the -th line contains the number (for ).
Exactly "cut and paste" operations are then performed on the document. Each operation acts on a group of consecutive lines: the "cut" removes the selected lines from the document, and the "paste" reinserts the removed block at another position among the remaining lines.
Given the sequence of "cut and paste" operations, determine the contents of the first ten lines of the document after all operations have been performed.
Input
The first line contains two integers and separated by a space: the number of lines in the document () and the number of "cut and paste" operations ().
Each of the next lines describes one operation, in the order in which they are executed, as three integers , , and separated by spaces, where and . Here and are the first and last lines of the block to be cut, numbered within the current document, and is the line, counted in the document after the block has been removed, after which the block must be inserted. If , the block is inserted at the very beginning of the document.
Output
Print ten lines containing the numbers written on the first ten lines of the document after all operations have been performed.