Huawei OD machine test-sequence description

 Question description

Given two integer sequences A and B of length n. Given q groups of queries, each query gives two integers x and y, find the number of i such that Ai >= x and Bi >= y.

Enter description

The first line gives two integers n and q.

The second line gives the sequence A, containing n integers.

The third line gives the sequence B, containing n integers.

The next q lines contain two integers x and y in each line, with the meanings described above.

Output description

For each set of queries, output the number of subscripts requested.

Example

enter

3 2
3 2 4
6 5 8
1 1
4 8

output

3
1

Remark

For 30% of the data, 1 <= n, q <= 100.

For 100% of the data, 1 <= n, q, Ai, Bi <= 10^5.

Code

import numpy


class Solution:
    def sequenceDescribe(self, n, q, arr1, arr2, arr3):
        res = []
        for i in range(q):
            x, y = arr3[i]
            flag = False
            j = 0
            while not flag and j <= n:
                if j >= n:
                    res.append(0)
                    flag = True
                elif j < n and (int(arr1[j]) < int(x) or int(arr2[j]) < int(y)):  # 不满足同时大于x,y,计数器+1
                    j += 1
                else:
                    res.append(n - j)
                    flag = True
        return res


if __name__ == '__main__':
    s = input("input n,q:").split(' ')
    n = int(s[0])
    q = int(s[1])
    arr1 = numpy.array(input("arr1:").split(' '))
    arr2 = numpy.array(input("arr2:").split(' '))
    arr3 = list()
    for i in range(q):
        arr = numpy.array(input("input x,y:").split(' '))
        arr3.append(arr)

    solution = Solution()
    print(solution.sequenceDescribe(n, q, arr1, arr2, arr3))

Guess you like

Origin blog.csdn.net/SD_JZZ/article/details/132305156