#P6683. [BalticOI 2020] 混合调料 (Day1)
[BalticOI 2020] 混合调料 (Day1)
Description
The head chef Serge of the famous restaurant Salt, Pepper & Garlic is ready to become a Michelin one-star chef. He has been told that tonight a secret judge will visit his restaurant.
Although he does not know the judge's name, he does know what dish the judge will order and the judge's taste preferences. Specifically, the judge wants the dish to contain salt, pepper powder, and garlic powder in a very precise ratio.
On a shelf in the kitchen, Serge has several bottles of mixed spices containing salt, pepper powder, and garlic powder. For each bottle, Serge knows the amounts of salt, pepper powder, and garlic powder in the mixture (in kilograms). By mixing spices from any number of bottles (and of course he may also use just one bottle), he can obtain spices in the required ratio.
In fact, not much spice is used in the dish, so we can assume the available amounts are sufficient. However, the numbers in the ratio of salt, pepper powder, and garlic powder required by the judge may be very large.
Now Serge wants to determine whether he can use the existing bottles to prepare a mixture that matches the judge's required ratio. If he can, what is the minimum number of bottles needed?
In addition, Serge may receive new bottles, or give existing bottles on the shelf to other chefs, meaning the set of bottles on the shelf will keep changing. Serge wants to solve the above problem after each change to the shelf.
For example, suppose the judge requires the ratio of salt, pepper powder, and garlic powder to be , and the shelf contains the following bottles:
| Bottle ID | Salt | Pepper | Garlic |
|---|---|---|---|
| 1 | 10 | 20 | 30 |
| 2 | 300 | 200 | 100 |
| 3 | 12 | 15 | 27 |
Then it is enough to mix all spices from bottle and kg of spices from bottle (which includes kg of salt, kg of pepper powder, and kg of garlic powder) to meet the requirement. Once bottle is removed, it becomes impossible to satisfy the judge's requirement.
Input Format
The first line contains three integers , meaning the ratio of salt, pepper powder, and garlic powder required by the judge is . For all , the mixture also satisfies the judge's requirement.
The next line contains an integer , meaning there will be changes to the bottles on the shelf. Initially, there are no bottles on the shelf.
The next lines each describe one change.
- If a bottle is added to the shelf, the line contains an uppercase letter
Aand three integers , representing the amounts of salt, pepper powder, and garlic powder in that bottle. Bottles are numbered starting from in the order they are added; that is, if this bottle is the -th bottle added to the shelf, then its ID is . - If a bottle is removed from the shelf, the line contains an uppercase letter
Rand an integer , representing the ID of the bottle to remove. It is guaranteed that the bottle with this ID is on the shelf.
Output Format
Output lines. On the -th line, output the minimum number of bottles needed to satisfy the judge's requirement after the -th change. In particular, if there is no way to satisfy the judge's requirement, output .
1 2 3
6
A 5 6 7
A 3 10 17
R 1
A 15 18 21
A 5 10 15
R 3
0
2
0
2
1
1
Hint
All testdata satisfy: , , , , .
- Subtask 1 (13 points): , .
- Subtask 2 (17 points): , .
- Subtask 3 (30 points): , .
- Subtask 4 (40 points): No special constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号