P16805 [Lanqiao Cup 2026 National Python A] Computing-Power and Electricity Coordination

Description

In $2026$, “computing-power and electricity coordination” was written into the government work report for the first time, and together with ultra-large-scale intelligent computing clusters, it was listed as a national-level new infrastructure project, supporting the construction of a nationwide integrated computing-power scheduling system. During the project implementation, national computing-power hub nodes need to manage a large number of computing units in real time. Each computing unit has an energy-efficiency value $v$ in the form of a non-negative integer. To optimize energy scheduling, the scheduling system needs to count the number of pairs of units that satisfy the “coordination condition”. Define two computing units $(i, j)$ as a coordinated pair if and only if: * $i < j$; * $\text{Fib}(v_i + v_j) = \text{Fib}(v_i) + \text{Fib}(v_j)$. Here, $\text{Fib}(x)$ denotes the $x$-th Fibonacci number. The Fibonacci sequence is defined as follows: * $\text{Fib}(0) = 0$; * $\text{Fib}(1) = 1$; * For $x \ge 2$, $\text{Fib}(x) = \text{Fib}(x-1) + \text{Fib}(x-2)$. Now, you need to maintain an initially empty pool of computing units and process $q$ operations: * $1\ k\ v$: Add $k$ computing units with energy-efficiency value $v$. * $2\ k\ v$: Remove at most $k$ computing units with energy-efficiency value $v$. If there are fewer than $k$ units with value $v$, remove all of them. * $3$: Query how many coordinated pairs of units there are in total at the moment. Please write a program to simulate the operation of this scheduling system and output the corresponding result for each query.

Input Format

The first line contains a positive integer $q$, indicating the number of operations. The next $q$ lines each describe one operation: * $1\ k\ v$: Add $k$ units with value $v$. * $2\ k\ v$: Remove at most $k$ units with value $v$. * $3$: Query the current total number of coordinated pairs.

Output Format

For each operation $3$, output one line containing one integer, indicating the current total number of coordinated pairs.

Explanation/Hint

### Constraints and Notes For $30\%$ of the testdata, $1 \le q \le 10^3$, $1 \le k \le 10$. For all testdata, $1 \le q \le 2 \times 10^5$, $0 \le v \le 10^9$, $1 \le k \le 10^3$. Translated by ChatGPT 5