#abc298c. C - Cards Query Problem
C - Cards Query Problem
Score : points
问题描述
我们有 个编号为 到 的空盒子,以及无限数量的空白卡片。
按照顺序处理 个查询请求。查询请求分为以下三种类型。
1 i j
在一张空白卡片上写上数字 ,并将其放入编号为 的盒子中。2 i
按升序报告盒子 中卡片上书写的全部数字。3 i
按升序报告包含数字 的卡片的所有盒子编号。
请注意以下几点:
- 对于第二类查询,如果盒子 中有多张卡片写着相同的数字,则应打印该数字,其重复次数等于拥有这些卡片的数量。
- 对于第三类查询,即使某个盒子包含多张带有数字 的卡片,也只需打印该盒子的编号一次。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have boxes numbered to that are initially empty, and an unlimited number of blank cards.
Process queries in order. There are three kinds of queries as follows.
1 i j
Write the number on a blank card and put it into box .2 i
Report all numbers written on the cards in box , in ascending order.3 i
Report all box numbers of the boxes that contain a card with the number , in ascending order.
Here, note the following.
- In a query of the second kind, if box contains multiple cards with the same number, that number should be printed the number of times equal to the number of those cards.
- In a query of the third kind, even if a box contains multiple cards with the number , the box number of that box should be printed only once.
Constraints
- For a query of the first kind:
- For a query of the second kind:
- Box contains some cards when this query is given.
- For a query of the third kind:
- Some boxes contain a card with the number when this query is given.
- At most numbers are to be reported.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Here, denotes the -th query, which is in one of the following formats:
Output
Respond to the queries of the second and third kinds in order.
For each of those queries, print one line containing the elements to be reported in ascending order, with spaces in between.
Sample Input 1
5
8
1 1 1
1 2 4
1 1 4
2 4
1 1 4
2 4
3 1
3 2
Sample Output 1
1 2
1 1 2
1 4
4
Let us process the queries in order.
- Write on a card and put it into box .
- Write on a card and put it into box .
- Write on a card and put it into box .
- Box contains cards with the numbers and .
- Print and in this order.
- Write on a card and put it into box .
- Box contains cards with the numbers , , and .
- Note that you should print twice.
- Boxes and contain a card with the number .
- Note that you should print only once, even though box contains two cards with the number .
- Boxes contains a card with the number .
Sample Input 2
1
5
1 1 1
1 2 1
1 200000 1
2 1
3 200000
Sample Output 2
1 2 200000
1
update @ 2024/3/10 12:21:56