P17675 [IO 2025 #4] The Horsemen's Expansion

Description

The Four Horsemen continue to hold their carefully planned shows around the world. They disappear at times and then appear on stage again, leaving many mysteries behind. Consider a dynamic set of magician teams. Team number $i$ is described by two parameters $x_i$ and $k_i$. Note that two different teams may have both parameters equal. Starting from day $t=1$, each team follows this infinite cycle of activity: - During the first $k_i$ days, the team performs actively with intensity $x_i$; - During the next $k_i$ days, the team disappears completely to prepare new magic and contributes nothing to the total "magic intensity". Then the cycle repeats: performing for $k_i$ days, staying silent for $k_i$ days, and so on. You need to handle queries from various observers (Interpol, the police, fans, and mysterious clients). They want to know the total "magic intensity" of all teams on a given day. Three types of operations are supported: 1. `+ x k`: a new magician team with parameters $x,k$ joins. 2. `- x k`: a team with parameters $x,k$ leaves. 3. `? t`: query the total performance intensity of all teams on day $t$. Help the observers answer all queries of the third type.

Input Format

The first line contains an integer $q$ ($1\le q\le 4\cdot 10^5$), the number of operations. Each of the next $q$ lines contains an operation of one of the three types above. The integers $x,k$ in operations of the first and second types are the parameters of the team being added or removed, with $1\le x\le 10^3$ and $1\le k\le 2\cdot 10^5$. The integer $t$ in operations of the third type is the day being queried, with $1\le t\le 2\cdot 10^5$. It is guaranteed that for every operation of the second type, the corresponding team was previously added by an operation of the first type and has not been removed yet.

Output Format

For each operation of the third type, output a single line with one integer: the total magic intensity on the queried day.

Explanation/Hint

Translated by QwenWork