#P7560. [JOISC 2021] フードコート (Day1)
[JOISC 2021] フードコート (Day1)
Description
There are Bookworm food shops, and families come to enjoy delicious food made from bookworms.
Because the food shops are very popular, customers need to line up. At the beginning, all queues are empty.
Today, all food shops open again, and events occur:
- Join event: In every food shop with an index in the interval , family joins the back of the queue. For each food shop that meets the condition, people are added to the back of the queue.
- Leave event: In every food shop with an index in the interval , if the queue has more than people, then the first people leave the queue; otherwise, everyone in the queue leaves.
- Freebie event: If the queue of food shop has at least people, then the food shop gives the -th person counting from the front of the queue one special bookworm; otherwise, the staff member eats the bookworm.
For each Freebie event, determine whether a customer receives a special bookworm. If yes, output which family the customer belongs to.
Input Format
The first line contains three integers , representing the number of food shops, the number of families, and the number of events.
In the next lines, each line starts with an integer :
- If , then four integers follow, describing a Join event.
- If , then three integers follow, describing a Leave event.
- If , then two integers follow, describing a Freebie event.
Output Format
For every Freebie event, output one integer per line:
- If a customer is given a special bookworm, output the family the customer belongs to.
- If the staff member eats the bookworm, output .
3 5 7
1 2 3 5 2
1 1 2 2 4
3 2 3
2 1 3 3
3 1 2
1 2 3 4 2
3 3 2
2
0
4
3 4 7
1 1 2 1 1
1 1 3 4 1
2 2 3 1
2 1 3 1
1 1 2 2 1
3 1 1
3 3 2
4
0
183326 218318 22
1 106761 160918 151683 574906362
3 68709 1
1 29240 156379 22166 957318472
1 14054 181502 82845 97183925
2 112033 122908 587808357
2 57819 160939 215041262
3 36674 524274467
1 35854 69866 32334 322730299
1 1384 7230 115069 454256926
1 44192 158235 8750 84192710
3 54457 1077490708
2 10592 110384 979714505
2 44594 79244 311724477
3 160965 97183926
1 88748 101697 39148 373927458
3 41166 58039001
1 91501 137591 205480 958877326
2 77775 169655 135756956
1 12497 57047 60918 15666764
1 47839 51716 144688 732270998
3 114514 774994894
3 48645 169986425
0
22166
32334
0
82845
8750
60918
Hint
Sample 1 Explanation
We use to denote the queue of the -th food shop, where is the front and is the back. Here, means that the person at position comes from family . In particular, means that the queue is currently empty.
According to the events in Sample 1:
- The -st Join event:
- The -nd Join event:
- The -rd Freebie event: the -rd person in the -nd food shop (from family ) is given a special bookworm.
- The -th Leave event:
- The -th Freebie event: the -st food shop has fewer than people, so the staff member eats the bookworm.
- The -th Join event:
- The -th Freebie event: the -nd person in the -rd food shop (from family ) is given a special bookworm.
Constraints and Notes
This problem uses bundled subtasks.
- Subtask 1 (2 pts): , satisfies Property A.
- Subtask 2 (5 pts): .
- Subtask 3 (7 pts): , satisfies Property B.
- Subtask 4 (21 pts): .
- Subtask 5 (15 pts): , satisfies Property A.
- Subtask 6 (13 pts): , satisfies Property C.
- Subtask 7 (26 pts): .
- Subtask 8 (11 pts): no special restrictions.
For of the data:
- .
- .
- For all Join events, , , .
- For all Leave events, , .
- For all Freebie events, , .
- There is at least one Freebie event.
There are the following properties:
- Property A: For all Join events and Leave events, .
- Property B: For all Join events, and .
- Property C: There are only Join events and Freebie events.
Note
Translated from The 20th Japanese Olympiad in Informatics Spring Training Camp Day1 C フードコート (Food Court) English version.
Translated by ChatGPT 5
京公网安备 11011102002149号