题目描述
blablabla
样例
blablabla
bisect库
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
c.sort()
res = 0
for i in b:
res += (bisect.bisect_left(a,i)) * (n-bisect.bisect_right(c,i))
print(res)
二分写法
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
res = 0
def check1(x):
l = 0
r = n - 1
while l < r:
mid = l + r + 1 >> 1
if a[mid] < x:
l = mid
else:
r = mid - 1
if a[l] < x:
return l + 1
else:
return 0
def check2(x):
l = 0
r = n - 1
while l < r:
mid = l + r >> 1
if c[mid] > x:
r = mid
else:
l = mid + 1
if c[l] > x:
return n - l
else:
return 0
for i in range(n):
res += check1(b[i]) * check2(b[i])
print(res)
blablabla