#P1188. Cut and Paste Text File
Cut and Paste Text File
Cut and Paste Text File
We are given a special text file with \(N\) lines. The \(i\)-th line contains the natural number \(i\) (i.e. the first line contains 1, the second line 2, and so on until \(N\)).
A series of consecutive cut and paste operations are performed on the file. Each operation is defined as follows:
- Select a contiguous block of lines from line \(l\) to line \(r\) (1-indexed) and remove them from the file.
- Insert the removed block immediately after the \(k\)-th line of the remaining file. If \(k=0\), the block is inserted at the beginning.
After all operations, output the contents of the first 10 lines of the modified file. If the file contains fewer than 10 lines, output all the lines.
inputFormat
The input begins with a line containing two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of lines in the file and \(M\) is the number of operations.
Each of the following \(M\) lines contains three integers \(l\), \(r\), and \(k\) (all 1-indexed, with the special case \(k=0\) allowed) which describe one operation. It is guaranteed that the operations are valid for the current state of the file.
outputFormat
Print the first 10 lines of the modified file after performing all the operations. Each line should contain exactly one number. If the file contains fewer than 10 lines, print all the lines.
sample
5 1
2 3 0
2
3
1
4
5
</p>