#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 1:1:11:1:1, 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 11 and 6060 kg of spices from bottle 22 (which includes 3030 kg of salt, 2020 kg of pepper powder, and 1010 kg of garlic powder) to meet the requirement. Once bottle 22 is removed, it becomes impossible to satisfy the judge's requirement.

Input Format

The first line contains three integers Sf,Pf,GfS_f,P_f,G_f, meaning the ratio of salt, pepper powder, and garlic powder required by the judge is Sf:Pf:GfS_f:P_f:G_f. For all α>0\alpha \gt 0, the mixture (αSf,αPf,αGf)(\alpha S_f,\alpha P_f, \alpha G_f) also satisfies the judge's requirement.

The next line contains an integer NN, meaning there will be NN changes to the bottles on the shelf. Initially, there are no bottles on the shelf.

The next NN lines each describe one change.

  • If a bottle is added to the shelf, the line contains an uppercase letter A and three integers Si,Pi,GiS_i,P_i,G_i, representing the amounts of salt, pepper powder, and garlic powder in that bottle. Bottles are numbered starting from 11 in the order they are added; that is, if this bottle is the ii-th bottle added to the shelf, then its ID is ii.
  • If a bottle is removed from the shelf, the line contains an uppercase letter R and an integer rir_i, representing the ID of the bottle to remove. It is guaranteed that the bottle with this ID is on the shelf.

Output Format

Output NN lines. On the ii-th line, output the minimum number of bottles needed to satisfy the judge's requirement after the ii-th change. In particular, if there is no way to satisfy the judge's requirement, output 00.

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: 1N1051 \leq N \leq 10^5, Sf,Pf,Gf0S_f,P_f,G_f \geq 0, 0<Sf+Pf+Gf1060 \lt S_f+P_f+G_f \leq 10^6, Si,Pi,Gi0S_i,P_i,G_i \geq 0, 0<Si+Pi+Gi1060 \lt S_i+P_i+G_i \leq 10^6.

  • Subtask 1 (13 points): N50N \leq 50, 0<Si+Pi+Gi1020 \lt S_i+P_i+G_i \leq 10^2.
  • Subtask 2 (17 points): N500N \leq 500, 0<Si+Pi+Gi1030 \lt S_i+P_i+G_i \leq 10^3.
  • Subtask 3 (30 points): N5000N \leq 5000, 0<Si+Pi+Gi1040 \lt S_i+P_i+G_i \leq 10^4.
  • Subtask 4 (40 points): No special constraints.

Translated by ChatGPT 5