#P4032. [Code+#2] 火锅盛宴
[Code+#2] 火锅盛宴
Description
In this hotpot feast, there is one spicy rich-broth hotpot and types of food, each available in unlimited quantity. We number the foods from to .
Each type takes a different amount of time to cook. The -th type takes units of time to get cooked. This means if you put a food into the pot at time , it will be cooked at time , and thereafter it will remain cooked until it is taken out.
Yazid and YJQQQAQ have different tastes: YJQQQAQ thinks all foods are equally tasty; Yazid thinks no two types have the same tastiness, and, coincidentally, the smaller the id, the more Yazid likes it. Poor SkyDec cannot eat spicy food, so he can only help Yazid and YJQQQAQ cook.
The whole feast lasts units of time. Throughout the feast, besides chatting and laughing, the most important thing is of course eating. At any integer time, any one of the following types of events may occur. We use an integer between and to denote the event type:
- : SkyDec puts one food with id into the hotpot.
- : Yazid searches the pot for a cooked food that he likes the most and takes one of that type. In particular, if there is no cooked food in the pot, Yazid will be angry.
- : YJQQQAQ searches the pot for food with id :
- If there is no such food in the pot, YJQQQAQ will be angry;
- If there is a cooked one of that type, YJQQQAQ will take one and eat it;
- If only uncooked ones of that type are in the pot, YJQQQAQ wants to know how much longer it will take for the one closest to being cooked (i.e., the one that has been in the pot the longest) to get cooked.
- : The mouthwatering SkyDec wants to know how many cooked foods with ids in are currently in the pot.
Input Format
Read from standard input.
This problem contains multiple testcases. The first line contains a positive integer , the number of testcases. Then for each testcase:
The first line contains a positive integer , the number of food types.
The second line contains space-separated positive integers , the cooking time required for each type.
The third line contains a positive integer , the number of events.
Then follow lines, each containing several space-separated nonnegative integers describing one event. Each line starts with two integers , denoting the time the event occurs and the event type, respectively.
- If or , then one positive integer follows, as described above;
- If , then nothing else follows;
- If , then two positive integers follow, as described above.
It is guaranteed that is strictly increasing in the order of input.
Output Format
For each operation with , output one line with the answer. For different values of , output as follows:
- For , if Yazid successfully takes a food, output the id of the food he takes; otherwise output .
- For , if YJQQQAQ successfully takes a food, output ; otherwise, if there is an uncooked food of that type in the pot, output how much longer it will take for the closest-to-cooked one of that type to get cooked; otherwise, output .
- For , output the number of cooked foods in the pot whose ids are within the specified range.
1
2
1 100
10
1 0 2
2 0 1
3 2 1
4 2 2
5 2 1
200 0 1
201 3 1 2
202 1
203 1
204 1
Succeeded!
97
YJQQQAQ is angry.
2
1
2
Yazid is angry.
Hint
For all testdata, it is guaranteed that , , , , , , , . It is guaranteed that is strictly increasing in the order of input.
From CodePlus December 2017 Contest, proudly presented by the Student Algorithm and Programming Association, Department of Computer Science and Technology, Tsinghua University.
Credit: idea/Wang Yuzhong, problem setter/Wang Yuzhong, testers/Lü Shiqing, Yang Jingqin.
Git Repo: https://git.thusaac.org/publish/CodePlus201712
Thanks to Tencent for supporting this contest.
Translated by ChatGPT 5
京公网安备 11011102002149号