思路:hash表,模拟即可。还是那个问题,对于多次输出,要用一个out数组来记录输出结果,最终一个print全部输出。为什么?因为print很亏时间,如果每次查询都print输出的话,必然会超时
注意:句子中会有重复的单词存在,因此我们应该用defaultdict(set)进行去重
代码:
import sys
from collections import defaultdict
input = lambda: sys.stdin.readline().strip()
import math
inf = 10 ** 18
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LI():
return input().split()
def LII():
return list(map(int, input().split()))
def LFI():
return list(map(float, input().split()))
fmax = lambda x, y: x if x > y else y
fmin = lambda x, y: x if x < y else y
isqrt = lambda x: int(math.sqrt(x))
'''
'''
def solve():
n = II()
d = defaultdict(set)
for i in range(1, n + 1):
string = LI()
for j in range(1, int(string[0]) + 1):
d[string[j]].add(i)
m = II()
out = []
for _ in range(m):
target = I()
out.append(' '.join(map(str, d[target])))
print('\n'.join(out))
t = 1
# t = II()
for _ in range(t):
solve()

京公网安备 11010502036488号