Esempio n. 1
0
def main ():
    read = stdin.readline
    write = stdout.write
    s = read ().rstrip ()
    n = int (read ())
    val = list (map (int, read ().split ()))
    xvwls = ""
    xc = [0]  # count of vowels until index of string
             # exclusive index position (index + 1 -> inclusive)
    cnt = 0
    for c in s:
        if c in {'a', 'e', 'i', 'o', 'u'}:
            xvwls += c
            cnt += 1
            xc.append (cnt)
        else: xc.append (cnt)
    len_xvwls = len (xvwls)
    #x = " "
    xs = []   # sum of vowel ranges
    xrv = []  # upper bound of ranges in xvwls
    sm = 0
    for v in val:
        if v < 0:
            #x += remv (s [-v:])
            #if dbg: eprint (remv (s [-v:]))
            sm += len_xvwls - xc [-v]
            xs.append (sm)
            xrv.append (len_xvwls)
            if dbg: eprint (xvwls [xc [-v] : len_xvwls])
        else:
            #x += remv (s [: v + 1])
            #if dbg: eprint (remv (s [: v + 1]))
            sm += xc [v + 1]
            xs.append (sm)
            xrv.append (xc [v + 1])
            if dbg: eprint (xvwls [: xc [v + 1]])
    #last = len (x) - 1
    q = int (read ())
    k = list (map (int, read ().split ()))
    if dbg:
        eprint (xc)
        eprint (xs)
        eprint (xrv)
        #eprint (last)
        eprint (xvwls)
    for q_ in range (q):
        #if k [q_] > last: write ("-1\n")
        #else: write (x [k [q_]] + '\n')
        if k [q_] > xs [-1]: write ("-1\n")
        else:
            ix = bisl (xs, k [q_])
            write (xvwls [xrv [ix] - xs [ix] + k [q_] - 1] + '\n')
def solve(a, b, n):
    if b[0] < a[-1]: return 0
    ans = 0
    if b[0] < a[0]: i = br(a, n, b[0])
    else: i = 0
    a_ = a[::-1]
    b_ = b[::-1]
    j = i + 1
    n_ = n - 1
    # bisect with reverse list 2 times slower for hackerearth testcases
    while j < n and i < n:
        j = n + 1 - bisl(b_, a[i]) - 1
        #print ("j - i", j, i, j - i, ans, end = "  ")
        nans = j - i
        if nans > ans: ans = nans
        i = n + 1 - bisr(a_, b[j + 1])
    return ans
def main():
    read = stdin.readline
    write = stdout.write
    n = int(read())
    a = list(map(int, read().split()))
    a.sort()
    a = list(accumulate(a))
    for i in range(n):
        a[i] //= i + 1
    ns = str(n) + '\n'
    mn = a[0]
    mx = a[-1]
    q = int(read())
    for q_ in range(q):
        k = int(read())
        if k > mx:
            write(ns)
            continue
        elif k <= mn:
            write("0\n")
            continue
        write(str(bisl(a, k)) + '\n')
Esempio n. 4
0
def solution(info, query):
    dic = {}
    for words in info:
        words = words.split()
        words, score = words[:-1], int(words[-1])
        for word in product(*zip(words, '-' * 4)):
            key = ''.join(word)
            dic.setdefault(key, [])
            dic[''.join(word)].append(score)

    for key in dic.keys():
        dic[key].sort()

    answer = []
    for q in query:
        q = q.replace('and ', '').split()
        q, score = ''.join(q[:-1]), int(q[-1])
        arr = dic.get(q)
        if arr == None:
            answer.append(0)
        else:
            answer.append(len(arr) - bisl(arr, score))

    return answer