#P7898. [Ynoi2006] wcirq

[Ynoi2006] wcirq

Problem Description

This is an interactive problem.

You need to perform nn primitive operations to maintain a sequence. The initial sequence is empty.

The ii-th primitive operation gives integers xi,  li,  rix_i,\;l_i,\;r_i, meaning: insert element ii before the xix_i-th position of the sequence (if xi=ix_i=i, it means inserting at the end of the sequence), and then query the set formed by the li,  li+1,  ,  ril_i,\;l_i+1,\;\dots,\;r_i-th elements of the sequence.

To answer these queries, you may operate on several sets. These sets are initially empty, indexed by integers from 11 to 2×1072\times 10^7.

You may spend 11 unit of the first type of cost to perform an insertion operation: insert element yy into the set with index xx. Before answering the query of the ii-th primitive operation, you must ensure 1yi1\le y\le i.

You may spend kk units of the second type of cost to answer a query: choose the sets with indices a1,  a2,  ,  aka_1,\;a_2,\;\dots,\;a_k, requiring that these sets are pairwise disjoint, and their union is the answer to the query.

After each primitive operation, the first-type/second-type costs of insertion operations and answering the query must not exceed the current subtask cost limits m1,  m2m_1,\;m_2. The cost of each primitive operation is calculated separately.

Input Format

You need to implement the function:

void solve(int x,int l,int r);

For each primitive operation, this function is called once, and the parameters x l r correspond to xi,  li,  rix_i,\;l_i,\;r_i.

Output Format

You may call the functions:

void op1(int x,int y);
void op2(int k);

Calling op1 means performing one insertion operation.

Calling op2 in order for a1,,aka_1,\dots,a_k means answering the query.

In the submitted code, you need to declare these two functions.

假设交互库调用了3次 `solve` 函数如下:

```cpp
solve(1,1,1);
solve(1,2,2);
solve(2,1,3);

```output1
以下给出了一种符合要求的对 `op1` 和 `op2` 的调用:

```cpp
op1(1,1);
op2(1);

此时序列为 (1)(1),编号1的集合为 {1}\{1\},第1次 solve 函数调用返回;

op2(1);

此时序列为 (2,1)(2,1),编号1的集合为 {1}\{1\},第2次 solve 函数调用返回;

op1(1,2);
op1(2,3);
op2(2);
op2(1);

此时序列为 (2,3,1)(2,3,1),编号1的集合为 {1,2}\{1,2\},编号2的集合为 {3}\{3\},第3次 solve 函数调用返回。


## Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078&nzhtl1477.

For $100\%$ of the testdata, it holds that $1\le n\le 10^6$; $1\le x_i\le i$; $1\le l_i\le r_i\le i$.

In the insertion operations or query answers you output, the set indices are in the range $1$ to $2\times 10^7$, and the $y$ in an insertion operation must be an element that already exists in the sequence.

Subtask 1 (10 points): guarantees $1\le n\le 10^3$.

Subtask 2 (10 points): guarantees $l_i=1,\;r_i=i$.

Subtask 3 (10 points): guarantees $x_i=i$.

Subtask 4 (20 points): guarantees $1\le n\le 10^4$.

Subtask 5 (10 points): guarantees $1\le n\le 10^5$.

Subtask 6 (20 points): the data is randomly generated, where $n=10^6$, and $(l_i,r_i)$ and $x_i$ are independently chosen uniformly at random among all possible cases.

Subtask 7 (20 points): no special restrictions.

For Subtask 6, $(m_1,m_2)=(64,64)$.

For all other subtasks, $(m_1,m_2)=(64,256)$.

Translated by ChatGPT 5