eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Ariel

King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton decides to set up a swimming competition in the kingdom Merfolk. Thousands of creatures come to take part in competition, that’s why it is too difficult to take the first place. For the King’s beloved daughter Ariel this competition is the first in her life. Ariel is very kind, so she wants to give a lot of gold medals. Ariel says, that it is unfair to make a single ranking list for creatures that are so different. It is really a good result to be the fastest small fish without tail in Merfolk! Ariel chooses \textbf{k} important traits (such as size, tailness, rapacity and so on). A creature can either possess a trait or not (there are no intermediate options). A \textit{score} is given for each creature (it doesn’t matter how it was calculated) and the list of possessed traits \textbf{f_1}, ..., \textbf{f_y} is also given. Ariel wants to know the place occupied by creature a in a competition among creatures, who have the same traits \textbf{h_1}, ..., \textbf{h_t}. So if creature \textbf{a} doesn’t have a trait \textbf{h_i}, then all creatures in the competition are without this trait. If creature \textbf{a}has a trait \textbf{h_i}, then all creatures in the competition have this trait. Other traits doesn’t matter. The winner of the competition is a creature with the maximum score. \InputFile The first line contains \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10^4}) and \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{10}). The next \textbf{n} lines contain information about creatures:\textbf{score} (\textbf{1} ≤ \textbf{score} ≤ \textbf{10^9}), \textbf{y} (\textbf{0} ≤ \textbf{y} ≤ \textbf{k}) --- the number of possessed traits, and \textbf{y} numbers \textbf{f_i} (\textbf{1} ≤ \textbf{f_i} ≤ \textbf{k}) --- ids of possessed traits. All \textbf{f_i} in one line are different. The next line contains \textbf{m} (\textbf{1} ≤ \textbf{m} ≤ \textbf{10^5}) --- the number of queries from Ariel. The next m lines describe queries: \textbf{a} (\textbf{1}≤ \textbf{a} ≤ \textbf{n}) --- the id of a creature, then \textbf{t} --- the number of traits, then \textbf{t} numbers \textbf{h_i}. All \textbf{h_i} in one line are different. \OutputFile For each query output the place of a creature a in ranking list amount the corresponded creatures. If several creatures have the same score all of them take the same place.
Лимит времени 1 секунда
Лимит использования памяти 256 MiB
Входные данные #1
3 2
100 1 1
50 1 2
30 2 1 2
12
1 2 1 2
1 1 1
1 1 2
1 0
2 0
2 1 1
2 1 2
2 2 2 1
3 0
3 2 1 2
3 1 2
3 1 1
Выходные данные #1
1
1
1
1
2
1
1
1
3
1
2
2
Источник ACM ICPC 2012-2013, NEERC, Moscow Subregion, Moscow, Sunday, October 21, 2012