Created
October 17, 2017 19:07
-
-
Save godmar/a9fdccda5ace301a7480578dd4930f52 to your computer and use it in GitHub Desktop.
This times out....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(raw_input()) | |
nums = list(map(int, raw_input().split())) | |
q = int(raw_input()) | |
for _ in xrange(q): | |
line = list(map(int, raw_input().split())) | |
idx = line[0] | |
numzz = set(line[2:]) | |
lo, hi, count = idx-1, n, 0 | |
while lo < hi: | |
mid = (lo + hi) / 2 | |
def isok(mid): | |
return reduce(lambda a, b: a | { b }, nums[lo:mid+1], set()).issubset(numzz) | |
if isok(mid): | |
count += 1 + mid - lo | |
lo = mid + 1 | |
else: | |
hi = mid | |
print count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment