#P8985. [北大集训 2021] 魔塔 OL

[北大集训 2021] 魔塔 OL

Background

CTT2021 D1T2

Problem Description

Byte Game Company has recently released a new game, Magic Tower Online. Players can control a hero to fight monsters in the game world. When the game was first released, there were no monsters in the magic tower. Then, qq events will happen one by one, and each event is one of the following three types:

  • + x y z a b: This means a new version of the game is released, and a new monster is added into the game. If this is the first monster added, then its ID is 11; otherwise, its ID is the ID of the last added monster +1+ 1. This monster is located on floor xx of the magic tower, its level is yy, and its difficulty is zz. If the player chooses to kill this monster, it costs aa HP. After killing it successfully, the player will obtain a potion that can restore bb HP and use it immediately.
  • - k: This means a new version of the game is released, and the monster with ID kk is removed due to balance issues, so it will no longer appear in the magic tower. Note: removed monsters still keep their IDs, and monsters added in the future will not reuse the IDs of removed monsters.
  • ? g l d: This is a query. A player wants to kill all monsters among the first gg floors of the magic tower whose level is at most ll and difficulty is at most dd. The player may kill these monsters in any order. Moving up to a new floor does not require killing all monsters on the current floor, and the battle process will not be affected by other monsters. Your task is to help the player compute the minimum initial HP the hero needs before setting out. If at any moment the hero's HP becomes negative, the game ends, and you must prevent this from happening.

Write a program to answer each query in order. Note that each query is only the player's thought experiment and will not actually kill any monster.

Input Format

The first line contains an integer qq, representing the number of events.

The next qq lines each start with a character, followed by several integers, describing each event in order.

The input guarantees 1q1500001\leq q\leq 150\,000, the total number of monsters does not exceed 5000050\,000, and the number of queries does not exceed 5000050\,000.

For the add-monster operation, it is guaranteed that 1x,y,z100001\leq x,y,z\leq 10\,000, and 0a,b1090\leq a,b\leq 10^9.

For the remove-monster operation, it is guaranteed that the operation is valid, and each monster will not be removed repeatedly.

For queries, it is guaranteed that 1g,l,d100001\leq g,l,d\leq 10\,000.

Output Format

For each query, output one line with one integer, which is the minimum initial HP of the hero before setting out.

10
+ 2 1 1 3 4
+ 1 2 2 2 5
? 2 2 2
+ 1 1 1 8 2
? 2 2 1
? 1 2 2
- 1
? 2 2 2
- 3
? 1 2 2

2
7
5
5
2

Hint

  1. (3 points) The total number of monsters does not exceed 88, and the number of queries does not exceed 88.
  2. (7 points) The total number of monsters does not exceed 50005\,000, and the number of queries does not exceed 50005\,000.
  3. (10 points) Potions do not restore HP, and the difficulty of all monsters is 11. That is, b=0b=0, and z=d=1z=d=1.
  4. (17 points) 1x,y,z,g,l,d51\leq x,y,z,g,l,d\leq 5.
  5. (30 points) The level and difficulty of all monsters are 11. That is, y=z=l=d=1y=z=l=d=1.
  6. (33 points) No additional constraints.

Translated by ChatGPT 5