Skip to content

Instantly share code, notes, and snippets.

@godmar
Created October 17, 2017 19:07
Show Gist options
  • Save godmar/a9fdccda5ace301a7480578dd4930f52 to your computer and use it in GitHub Desktop.
Save godmar/a9fdccda5ace301a7480578dd4930f52 to your computer and use it in GitHub Desktop.
This times out....
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