atcoder#ABC298C. [ABC298C] Cards Query Problem
[ABC298C] Cards Query Problem
Score : points
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.
- 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.
- 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.
5
8
1 1 1
1 2 4
1 1 4
2 4
1 1 4
2 4
3 1
3 2
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.
- 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.
- 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 .
- Note that you should print only once, even though box contains two cards with the number .
- Boxes contains a card with the number .
1
5
1 1 1
1 2 1
1 200000 1
2 1
3 200000
1 2 200000
1