P7898 [Ynoi2006] wcirq
Description
**This is an interactive problem.**
You need to perform $n$ primitive operations to maintain a sequence. The initial sequence is empty.
The $i$-th primitive operation gives integers $x_i,\;l_i,\;r_i$, meaning: insert element $i$ before the $x_i$-th position of the sequence (if $x_i=i$, it means inserting at the end of the sequence), and then query the set formed by the $l_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 $1$ to $2\times 10^7$.
You may spend $1$ unit of the first type of cost to perform an insertion operation: insert element $y$ into the set with index $x$. Before answering the query of the $i$-th primitive operation, you must ensure $1\le y\le i$.
You may spend $k$ units of the second type of cost to answer a query: choose the sets with indices $a_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 $m_1,\;m_2$. The cost of each primitive operation is calculated separately.
Input Format
You need to implement the function:
```cpp
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 $x_i,\;l_i,\;r_i$.
Output Format
You may call the functions:
```cpp
void op1(int x,int y);
void op2(int k);
```
Calling `op1` means performing one insertion operation.
Calling `op2` in order for $a_1,\dots,a_k$ means answering the query.
In the submitted code, you need to declare these two functions.
Explanation/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