#P4032. [Code+#2] 火锅盛宴

[Code+#2] 火锅盛宴

Description

In this hotpot feast, there is one spicy rich-broth hotpot and nn types of food, each available in unlimited quantity. We number the foods from 11 to nn.

Each type takes a different amount of time to cook. The ii-th type takes sis_i units of time to get cooked. This means if you put a food ii into the pot at time TT, it will be cooked at time T+siT+s_i, 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 10910^9 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 44 types of events may occur. We use an integer opop between 00 and 33 to denote the event type:

  • 0 id0\ id: SkyDec puts one food with id idid into the hotpot.
  • 11: 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.
  • 2 id2\ id: YJQQQAQ searches the pot for food with id idid:
    • 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.
  • 3 l r3\ l\ r: The mouthwatering SkyDec wants to know how many cooked foods with ids in [l,r][l,r] are currently in the pot.

Input Format

Read from standard input.

This problem contains multiple testcases. The first line contains a positive integer TT, the number of testcases. Then for each testcase:

The first line contains a positive integer nn, the number of food types.

The second line contains nn space-separated positive integers s1,s2,,sns_1,s_2,\cdots,s_n, the cooking time required for each type.

The third line contains a positive integer QQ, the number of events.

Then follow QQ lines, each containing several space-separated nonnegative integers describing one event. Each line starts with two integers t,opt,op, denoting the time the event occurs and the event type, respectively.

  • If op=0op=0 or op=2op=2, then one positive integer idid follows, as described above;
  • If op=1op=1, then nothing else follows;
  • If op=3op=3, then two positive integers l,rl,r follow, as described above.

It is guaranteed that tt is strictly increasing in the order of input.

Output Format

For each operation with op0op\neq 0, output one line with the answer. For different values of opop, output as follows:

  • For op=1op=1, if Yazid successfully takes a food, output the id of the food he takes; otherwise output Yazid is angry. ⁣ ⁣\text{``\texttt{Yazid is angry.}''}\!\!.
  • For op=2op=2, if YJQQQAQ successfully takes a food, output  ⁣ ⁣Succeeded! ⁣ ⁣\!\!\text{``\texttt{Succeeded!}''}\!\!; 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  ⁣ ⁣YJQQQAQ is angry. ⁣\!\!\text{``\texttt{YJQQQAQ is angry.}''}\!.
  • For op=3op=3, 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 T4T\leq 4, n100,000n\leq 100,000, Q500,000Q\leq 500,000, 1si1081\leq s_i\leq 10^8, 1t1091\leq t\leq 10^9, op{0,1,2,3}op\in\{0, 1, 2, 3\}, 1idn1\leq id\leq n, 1lrn1\leq l\leq r\leq n. It is guaranteed that tt 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