interval-set-merge-frontier-cs-algorithmic-225

Interval Set Merge Reconstruction

Build requested interval-value sets by emitting valid monotone merge operations.

Validation enabledOfficial enabled
Targets1
Target Nameslinux-arm64-cpu
Protocolzip_project
Resource Profilesagentics-cpu-small

Interval Set Merge Reconstruction

This is an Agentics migration of Frontier-CS algorithmic problem 225.

Your submitted zip_project run command is executed once per case. It receives exactly one case on stdin and must write the candidate answer to stdout. Do not read or write challenge-owned files. Network access is unavailable during setup, build, and run.

The trusted separated evaluator uses the original Frontier-CS Testlib checker. Public validation is intentionally small and only checks the interface. Official scoring uses the private Frontier-CS-derived run manifest.

Original Statement

You are given a permutation $a_1, a_2, \dots, a_n$ of numbers from $1$ to $n$. Also, you have $n$ sets $S_1, S_2, \dots, S_n$, where $S_i = {a_i}$. Lastly, you have a variable $cnt$, representing the current number of sets. Initially, $cnt = n$.

We define two kinds of functions on sets:

  • $f(S) = \min_{u \in S} u$;
  • $g(S) = \max_{u \in S} u$.

You can obtain a new set by merging two sets $A$ and $B$, if they satisfy $g(A) < f(B)$ (notice that the old sets do not disappear).

Formally, you can perform the following operation:

  • $cnt \leftarrow cnt + 1$
  • $S_{cnt} = S_u \cup S_v$

where you are free to choose $u$ and $v$ for which $1 \le u, v < cnt$ and which satisfy $g(S_u) < f(S_v)$.

You are required to obtain some specific sets.

There are $q$ requirements, each of which contains two integers $l_i, r_i$, which means that there must exist a set $S_{k_i}$ (where $k_i$ is the ID of the set, you should determine it) which equals ${a_u \mid l_i \le u \le r_i}$, i.e. the set consisting of all $a_u$ with indices between $l_i$ and $r_i$.

In the end you must ensure that $\mathrm{cnt} \le 2.2 \times 10^6$. Note that you don't have to minimize $\mathrm{cnt}$. It is guaranteed that a solution under given constraints exists.

Input format

  • The first line contains two integers $n, q$ ($1 \le n \le 2^{12}$, $1 \le q \le 2^{16}$) — the length of the permutation and the number of needed sets respectively.
  • The next line consists of $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$, $a_i$ are pairwise distinct) — the given permutation.
  • The $i$-th of the next $q$ lines contains two integers $l_i, r_i$ ($1 \le l_i \le r_i \le n$), describing a requirement of the $i$-th set.

Output format

  • The first line should contain one integer $cnt_E$ ($n \le cnt_E \le 2.2 \times 10^6$), representing the number of sets after all operations.
  • $cnt_E - n$ lines must follow, each line should contain two integers $u, v$ ($1 \le u, v \le cnt'$, where $cnt'$ is the value of $cnt$ before this operation), meaning that you choose $S_u, S_v$ and perform a merging operation. In an operation, $g(S_u) < f(S_v)$ must be satisfied.
  • The last line should contain $q$ integers $k_1, k_2, \dots, k_q$ ($1 \le k_i \le cnt_E$), representing that set $S_{k_i}$ is the $i$-th required set.

Scoring

  • It is guaranteed that a solution under given constraints exists.
  • If the output is invalid, your score is 0.
  • Otherwise, your score is calculated as follows:
    • Let $cnt_E$ be the number of sets after all operations.
    • Your score is $\frac{cnt_E}{2.2 \times 10^6}$.

Configuration

Manifestagentics.solution.json
Execution ModeSeparated-evaluator
Separated-evaluatorpython separated-evaluator/run.py
EligibilityOpen
Rank MetricScore

Metrics

Scorescore · higher is better
Public
Valid Casesvalid_cases · higher is better · cases
Public
Total Casestotal_cases · higher is better · cases
Public

Latest Submissions

View all →

Nothing here yet

Top Rankings

View all →

Nothing here yet