| UFPE Starters Final Try-Outs 2026 |
|---|
| Finished |
After qualifying for the ICPC Worlds, the $$$N$$$ MaratonaCIn members decided to celebrate with a trip together. They found $$$K$$$ tourist hotspots, conveniently numbered from $$$1$$$ to $$$K$$$. There is, however, a problem: maratonistas (the members of MaratonaCIn) are notoriously picky. The $$$i$$$-th member has $$$m_i$$$ places they will refuse to go.
Wanting to make everyone happy, they are willing to split into groups as long as each group is a contiguous interval of the original list. In order to help Coach Palão plan the trip, answer $$$Q$$$ queries: what places can be visited if he brings the members in a given interval $$$[l, r]$$$?
The first line contains two integers $$$N$$$ ($$$1 \le N \le 10^5$$$) and $$$K$$$ ($$$1 \le K \le 60$$$).
Then, $$$N$$$ lines follow. The $$$i$$$-th line starts with an integer $$$m_i$$$ ($$$0 \le m_i \le K$$$), the amount of places the $$$i$$$-th person refuses to go. After that, $$$m_i$$$ integers $$$p_j$$$ ($$$1 \le p_j \le K$$$), the numbers of the places.
Then one integer $$$Q$$$ ($$$1 \le Q \le 2 \cdot 10^5$$$), the number of queries.
Finally, $$$Q$$$ lines containing two integers $$$l$$$ $$$r$$$, ($$$1 \le l \le r \le N$$$).
For every query, output the places the group consisting of every maratonista from $$$l$$$ to $$$r$$$ can go, in ascending order. If there isn't anywhere they can go, output $$$-1$$$ instead.
5 61 13 2 4 62 2 502 1 341 33 53 41 5
3 4 6 1 3 4 6 -1
Note that the output must be in strictly ascending order or your answer might not be accepted.
| Name |
|---|


