Exemple #1
0
def solution(info, query):
    x = {}
    for i in info:
        a = i.split()
        key = a[0][0] + a[1][0] + a[2][1] + a[3][1]
        if not key in x: x[key] = []
        x[key].append(int(a[4]))

    for (key, arr) in x.items():
        arr.sort()

    answer = []
    for _q in query:
        q = list(map(lambda x: x.strip(), _q.split("and")))
        q[-1], score = q[-1].split()
        a = "cjp" if q[0] == '-' else q[0][0]
        b = "bf" if q[1] == '-' else q[1][0]
        c = "ue" if q[2] == '-' else q[2][1]
        d = "hi" if q[3] == '-' else q[3][1]
        a, b, c, d = map(list, [a, b, c, d])
        score = int(score)

        cnt = 0
        for a0 in a:
            for b0 in b:
                for c0 in c:
                    for d0 in d:
                        key = a0 + b0 + c0 + d0
                        if not key in x: continue
                        arr = x[key]
                        cnt += len(arr) - lower_bound(arr, score)
        answer.append(cnt)

    return answer
Exemple #2
0
def findNumOfPair(array, n):
    array = sorted(array)
    ans = 0
    for i in range(n):
        if (array[i] <= 0):
            continue
        j = lower_bound(array, -array[i] + 1)
        ans += i - j
    return ans
Exemple #3
0
 def increasingTriplet(self, nums: List[int]) -> bool:
     increasing = [0] * len(nums)
     length = 0
     for i, num in enumerate(nums):
         index = lower_bound(increasing, num, 0, length)
         if index == length: length += 1
         if length >= 3: return True
         increasing[index] = num
     return False
Exemple #4
0
def find_num_of_pairs(a, n):
	a = sorted(a)
	ans = 0
	for i in range(n):
		if a[i] <= 0:
			continue
		j = lower_bound(a, -a[i]+1)
		ans += i-j
	return ans
Exemple #5
0
def findNumOfPair(a, n):
    # code here
    a = sorted(a)
    result = 0
    for i in range(n):
        if (a[i] <= 0):
            continue
        j = lower_bound(a, -a[i] + 1)
        result += i - j
    return result
    def lengthOfLIS(self, nums: List[int]) -> int:
        n = len(nums)
        a = [0] * n
        length = 0
        for i in range(n):
            idx = lower_bound(a, nums[i], 0, length)
            if idx >= length: length += 1
            a[idx] = nums[i]

        return length
def findNumOfPair(array, n): 
    array = sorted(array)
    count = 0
    for i in range(n):
        if array[i] <= 0:
            continue
        j = lower_bound(array,-array[i]+1)
        count += i-j
        
    return count
        
Exemple #8
0
def convert(arr, n):

    # Create a copy of arrp[] in temp and
    # sort the temp array in increasing order
    temp = [0] * n
    for i in range(n):
        temp[i] = arr[i]

    temp.sort()

    # Traverse all array elements
    for i in range(n):

        # lower_bound() Returns pointer to the first element
        # greater than or equal to arr[i]
        arr[i] = lower_bound(temp, arr[i]) + 1
def findFrequency(arr,n,left,right,element):
    #lower bound gives takes list of locations
    #where element is present in orgnal array
    #and the left range
    # and returns the index of element from
    #that list which is greater equal to given
    #left range.
    a=lower_bound(store[element],left)
    #upper bound gives takes list of locations
    #where element is present in orgnal array
    #and the right range
    # and returns the index of element from
    #that list which is less than or equal to
    #given right range.

    b=upper_bound(store[element],right)

    #return last index where element exists
    #in range - the first index where it
    #exist of the list of occurances

    return b-a 
Exemple #10
0
def main():
    q = int(input())
    names = []
    customers_list = [dict() for i in range(q)]
    for i in range(q):
        row = input().split()
        k = int(row[0])
        for j in range(k):
            names.append(row[2 * j + 1])
            customers_list[i][row[2 * j + 1]] = int(row[2 * j + 2])
    names.sort()
    mark = [False for i in range(len(names))]
    id_heap = []
    day_heap = []
    for i in range(q):
        for a_name, remaining_days in customers_list[i].items():
            index = lower_bound(names, a_name)
            heapq.heappush(id_heap, (index, remaining_days + i))
            heapq.heappush(day_heap, (remaining_days + i, index))
        result = []
        while (len(day_heap) > 0) and (day_heap[0][0] == i + 1):
            index = day_heap[0][1]
            heapq.heappop(day_heap)
            if not mark[index]:
                mark[index] = True
                result.append(names[index])
        while (len(id_heap) > 0) and mark[id_heap[0][0]]:
            heapq.heappop(id_heap)

        if len(id_heap) > 0:
            index = id_heap[0][0]
            mark[index] = True
            result.append(names[index])
            heapq.heappop(id_heap)

        print(' '.join(sorted(result)))
def count_displacements(a, n):
    ans = 0
    for i in range(0, n - 1):
        ans += lower_bound(sorted(a[i + 1:]), a[i])
    return ans
Exemple #12
0
from bisect import bisect_left as lower_bound

n = int(input())
a, b, c, d = map(int, input().replace('/', ' ').split())

points = [map(int, input().split()) for _ in range(n)]
rpoints = [(-a * x + b * y, -(-c * x + d * y)) for x, y in points]
spoints = sorted([(x, y) for x, y in rpoints if x > 0 and y > 0],
                 key=lambda x: (x[0], -x[1]))

F = []
for x, y in spoints:
    i = lower_bound(F, y)
    if i == len(F):
        F.append(y)
    else:
        F[i] = y

print(len(F))
from bisect import bisect_left as lower_bound

n, x = (int(x) for x in input().split())
arr = sorted(int(x) for x in input().split())

p = lower_bound(arr, x)
print(x - p + (p < len(arr) and arr[p] == x))
from bisect import bisect_left as lower_bound

n = int(input())
a, b, c, d = map(int,input().replace('/',' ').split())

points = [map(int,input().split()) for _ in range(n)]
rpoints = [(-a*x+b*y,-(-c*x+d*y)) for x,y in points]
spoints = sorted([(x,y) for x,y in rpoints if x>0 and y>0], key=lambda x: (x[0], -x[1]))

f = []
for x,y in spoints:
    i = lower_bound(f,y)
    if i == len(f):
        f.append(y)
    else:
        f[i] = y

print(len(f))
Exemple #15
0
from bisect import bisect_left as lower_bound

a = ['a', 'z', 'g', 'd', 'd', 'e', 'w']
a.sort()
print(a)
while True:
    word = input()
    print(lower_bound(a, word))