DMOPC '21 Contest 7 P2 - Knitting Scarves

View as PDF

Submit solution


Points: 7
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Kanna's scarf is coloured with patches of colours that can be numbered from 1 to N. Kanna likes her scarf in a certain pattern and Edward needs to be able to recreate this scarf. Kanna is going to give sequential instructions of how she would like her scarf, starting from the default pattern where the patches are numbered in increasing order. At the i-th step, she wants Edward to perform a knitting operation, taking the continuous segment of colours starting with colour Li and ending with colour Ri and moving it right after colour Ki if 1KiN. If Ki=0, then she wants the continuous segment to be moved to the very front of the scarf.

Can you tell Edward what the scarf should look like after all Q steps?

Constraints

1N106

1Q5×105

1Li,RiN

0KiN

After the first i1 steps have been performed:

  • Colour Li appears no later than colour Ri in the scarf.
  • Ki is not contained in the continuous segment of colours starting with colour Li and ending with colour Ri.

Input Specification

The first line contains 2 integers N and Q.

The i-th of the following Q lines contains 3 integers Li, Ri, and Ki.

Output Specification

As a space-separated sequence of N integers, output the sequence of colours on the scarf after all Q steps have been performed.

Sample Input

Copy
6 3
4 5 1
5 6 0
2 2 3

Sample Output

Copy
5 3 2 6 1 4

Explanation

Initially, the colours on the scarf are [1,2,3,4,5,6].

After the first step, the colours on the scarf are [1,4,5,2,3,6].

After the second step, the colours on the scarf are [5,2,3,6,1,4].

After the final step, the colours on the scarf are [5,3,2,6,1,4].


Comments

There are no comments at the moment.