#P7898. Interactive Sequence Maintenance and Set Operations

    ID: 21083 Type: Default 1000ms 256MiB

Interactive Sequence Maintenance and Set Operations

Interactive Sequence Maintenance and Set Operations

This is an interactive problem.

You are required to perform \(n\) original operations to maintain a sequence. Initially, the sequence is empty.

For the \(i\)-th operation, you are given five integers \(x_i,\; l_i,\; r_i,\; m_1,\; m_2\) where:

  • Insertion: Insert element \(i\) into the sequence. If \(x_i = i\), then insert the element at the end of the sequence; otherwise, insert the element before the \(x_i\)-th element of the sequence.
  • Query: After the insertion, consider the subsequence from positions \(l_i\) to \(r_i\) (inclusive). Let \(Q_i\) be the set of elements in that subsequence (i.e. the unique elements).

Additionally, you are allowed to perform operations on sets (with indices from \(1\) to \(2\times10^7\)), with two types of operations defined below:

  • Type-1 (Insertion) Operation: It costs 1 unit to insert an element \(y\) into a set with index \(x\). Before answering the \(i\)-th query, every element \(y\) present in any set must satisfy \(1 \le y \le i\).
  • Type-2 (Query Answering) Operation: It costs \(k\) units to answer a query by selecting \(k\) sets that are pairwise disjoint such that their union exactly equals the query answer.

For each original operation, the costs for type-1 and type-2 operations must not exceed the current subtask limits \(m_1\) and \(m_2\) respectively. The cost for each original operation is computed separately.

Note: Although the background involves managing sets with cost constraints, you only need to simulate the sequence operations and output the query answers. For each operation, output the query answer as the sorted set (in ascending order) of the unique elements in the queried segment.

inputFormat

The first line contains an integer \(n\) \( (1 \le n \le 10^5)\), representing the number of operations.

Each of the next \(n\) lines contains five integers \(x_i,\; l_i,\; r_i,\; m_1,\; m_2\) describing the \(i\)-th operation, where:

  • \(x_i\) \( (1 \le x_i \le i)\): If \(x_i = i\), insert element \(i\) at the end; otherwise, insert element \(i\) before the \(x_i\)-th element.
  • \(l_i\) and \(r_i\) \( (1 \le l_i \le r_i \le current\; sequence\; length)\): Denote the query range after the insertion.
  • \(m_1\) and \(m_2\): The cost limits for type-1 and type-2 operations for this operation (their values are provided for context but are not used in the simulation).

outputFormat

For each operation, output one line containing the query answer. The answer is the sorted set (in ascending order) formed by the unique elements in the subsequence from position \(l_i\) to \(r_i\) (inclusive). Output the elements separated by a single space.

sample

3
1 1 1 100 100
1 1 2 100 100
3 1 3 100 100
1

1 2 1 2 3

</p>