HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


51023 - Preparing Keyword Index

Guest
• Review clarifications (2)

Volume problems

• 51021 - Number of Nodes
• 51044 - Number of Trees
• 51010 - Max Sequential Sum
• 51086 - Top popular student
• 51072 - Castle on chessboard
• 51015 - Student Scholarships
• 51082 - Sum is equal to K - 1
• 51020 - Number of nodes removed
• 51023 - Preparing Keyword Index
• 51075 - Shortest Path for Bishop
• 50774 - Hot Potato
• 50688 - Epoka Furgon
• 50750 - Service Time - 2
• 50771 - BST Level Sum
• 50536 - Epoka Furgon Shpk
• 50773 - Balanced Sum Tree
• 50757 - National Elections - 1

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Preparing Keyword Index

Question: The books have indexes at the end, so that, people can search for a specific topic or section using a keyword. You are given the index pages with keywords. Then, you are asked to prepare the index of the book. Write a program which reads the page and keyword information. Then, the program should print the index pages for a given word.

Input specification: In the first line, you will be given two integers: the number of pages (n) with keywords, and the max number of index pages to keep (max). The following n lines start with two integers the page number (p) and the number of keywords (k) in that page where keywords are all in lowercase and contain only 26 English letters with no special char. Then, you will be given k keywords in the same line. After that, you will be given a keyword. Where 1 ≤ n ≤ 40,000, 1 ≤ max ≤ 100 and there may at most 50 keywords in one page.

Output specification: Show the pages that the given keyword appears in ascending order. Show 0, if it doesn't appear on any page. Note: Keep at most max unique-index pages for every keyword. The max index pages will be decided according to the order of appearance. The index page appearing on the after max pages or later will be ignored.

Sample Input
4 2
1 3 index book index
4 1 keyword
7 3 index search appear
5 3 index keyword search
index
Sample Output
1 7

Explanation: There are four pages with keywords and maximum (the first) 2 index pages will be shown. Page 1 contains 2 keywords: book and index, and, there are 5 keywords in total. The following is the list of keywords and their appearing pages:

  • appear 7
  • book 1
  • index 1 5 7
  • keyword 4 5
  • search 5 7
Although, index word appears on three pages: 1, 5 and 7, the program should show only the first two pages 1 7 according to order of appearance, because Max pages given as 2.



Для отправки решений необходимо выполнить вход.

www.contester.ru