input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) cnt = 0 for a in A: for b in B: for c in C: if a < b < c: cnt += 1 print(cnt)
import bisect n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) cnt = 0 for b in B: mid = bisect.bisect_left(A, b) bottom = n - bisect.bisect_right(C, b) cnt += mid*bottom print(cnt)
p03557
import bisect as bi n = int(eval(input())) kariA = list(map(int,input().split())) kariB = list(map(int,input().split())) kariC = list(map(int,input().split())) A = sorted(kariA) B = sorted(kariB) C = sorted(kariC) count = 0 for c in C: for b in B[:bi.bisect_left(B,c)]: count += bi.bisect_left(A,b) print(count)
import bisect as bi n = int(eval(input())) kariA = list(map(int,input().split())) kariB = list(map(int,input().split())) kariC = list(map(int,input().split())) A = sorted(kariA) B = sorted(kariB) C = sorted(kariC) count = 0 Clength = len(C) for b in B: count += bi.bisect_left(A,b)*(Clength - bi.bisect_right(C,b)) print(count)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 def func(array, value): ng = -1 ok = len(array) #if value while ok - ng > 1: mid = (ok + ng)//2 if array[mid] < value: ng = mid elif array[mid] >= value: ok = mid return ok for a in A: b_idx = func(B, a + 1) if b_idx == len(B): break #print('a', a) #print('B[b_idx:]',B[b_idx:]) for b in B[b_idx:]: c_idx = func(C, b + 1) #print('b',b) #print('C[c_idx:]',C[c_idx:]) if c_idx == len(C): break #print(a, b_idx, c_idx) ans += len(C) - c_idx print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 def low_func(array, value): ng = -1 ok = len(array) #if value while ok - ng > 1: mid = (ok + ng)//2 if array[mid] < value: ng = mid elif array[mid] >= value: ok = mid return ok def up_func(array, value): ok = -1 ng = len(array) #if value while abs(ok - ng) > 1: mid = (ok + ng)//2 if array[mid] <= value: ok = mid elif array[mid] > value: ng = mid return ok for b in B: a_idx = up_func(A, b - 1) if a_idx == -1: continue c_idx = low_func(C, b + 1) if c_idx == len(C): break ans += (a_idx + 1)*(len(C) - c_idx) print(ans)
p03557
import bisect as bs n = int(eval(input())) a_l = list(map(int, input().split())) b_l = list(map(int, input().split())) c_l = list(map(int, input().split())) a_l.sort() b_l.sort() c_l.sort() ans = 0 for i in range(n): index_1 = bs.bisect_right(b_l,a_l[i]) for j in range(index_1,n): index_2 = bs.bisect_right(c_l,b_l[j]) ans += (n-index_2) print(ans)
import bisect as bs n = int(eval(input())) a_l = list(map(int, input().split())) b_l = list(map(int, input().split())) c_l = list(map(int, input().split())) a_l.sort() b_l.sort() c_l.sort() ans = 0 for b in b_l: ans += bs.bisect_left(a_l,b) * (n-bs.bisect_right(c_l,b)) print(ans) ''' 以下の方法だと、N*logN*logN for i in range(n): index_1 = bs.bisect_right(b_l,a_l[i]) for j in range(index_1,n): index_2 = bs.bisect_right(c_l,b_l[j]) ans += (n-index_2) print(ans) '''
p03557
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) #リストをソート a = sorted(a) b = sorted(b) c = sorted(c) # x以上のイテレータを def lower_bound(arr , x): l = 0 r = len(c) for j in range(100): mid = (l + r) // 2 # print(l , r , mid) if x <= arr[mid]: r = mid else: l = mid return r count = 0 for i in range(n): a_count = lower_bound(a , b[i]) c_count = len(c) - lower_bound(c , b[i] + 1) count += a_count * c_count print(count)
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) #リストをソート a = sorted(a) b = sorted(b) c = sorted(c) # x以上のイテレータを def lower_bound(arr , x): l = 0 r = len(c) for j in range(30): mid = (l + r) // 2 # print(l , r , mid) if x <= arr[mid]: r = mid else: l = mid return r count = 0 for i in range(n): a_count = lower_bound(a , b[i]) c_count = len(c) - lower_bound(c , b[i] + 1) count += a_count * c_count print(count)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() def binary_search(k, x): index = bisect.bisect_right(k, x) if index == len(k): return False else: # index + 1個している return index + 1 ans = 0 for up in a: indexed_b = binary_search(b, up) b_cnt = n - (indexed_b - 1) if b_cnt > len(b): break for middle in b[indexed_b-1:]: indexed_c = binary_search(c, middle) c_cnt = n - (indexed_c - 1) ans += c_cnt print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() def binary_upper(k, x): return len(k) - bisect.bisect_right(k, x) def binary_lower(k, x): return bisect.bisect_left(k, x) ans = 0 for middle in b: cnt_a = binary_lower(a, middle) cnt_c = binary_upper(c, middle) ans += cnt_a * cnt_c print(ans)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() cnt = 0 for i in a: x = bisect.bisect_right(b,i) for j in b[x:]: y = bisect.bisect_right(c,j) cnt += n-y b = b[x:] print (cnt)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() cnt = 0 for i in b: x = bisect.bisect_left(a,i) y = bisect.bisect_right(c,i) cnt += x*(n-y) print (cnt)
p03557
import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(n): canB = bisect.bisect_right(B, A[i]) if canB == n: continue else: for j in range(canB, n): canC = bisect.bisect_right(C, B[j]) ans += (n - canC) print(ans)
import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(n): canA = bisect.bisect_left(A, B[i]) canC = bisect.bisect_right(C, B[i]) ans += (canA)*(n-canC) print(ans)
p03557
import bisect n = int(eval(input())) A = sorted([int(i) for i in input().split()] ) B = sorted([int(i) for i in input().split()] ) C = sorted([int(i) for i in input().split()] ) result = 0 for c in C: B_sub = B[:bisect.bisect_left(B,c)] for b in B_sub: result += bisect.bisect_left(A,b) print(result)
import bisect n = int(eval(input())) A = sorted([int(i) for i in input().split()] ) B = sorted([int(i) for i in input().split()] ) C = sorted([int(i) for i in input().split()] ) b_count = [] pre_b = 0 for b in B: current_count = bisect.bisect_left(A,b) b_count.append(pre_b + current_count) pre_b += current_count result = 0 for c in C: index = bisect.bisect_left(B,c) if index == 0: continue result += b_count[index-1] print(result)
p03557
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() B.sort() C.sort() ans = 0 left = 0 for a in A: right = left while left < N and a >= B[left]: left += 1 if N <= left: break for b in B[left:]: while right < N and b >= C[right]: right += 1 if N <= right: break ans += N-right print(ans) if __name__ == '__main__': main()
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() B.sort() C.sort() def is_ok1(mid, S, K): if K <= S[mid]: return True else: return False def is_ok2(mid, S, K): if K < S[mid]: return True else: return False def binary_search_meguru(S, K, is_ok): left = -1 right = N while right - left > 1: mid = left + ((right - left) // 2) if is_ok(mid, S, K): right = mid else: left = mid return right ans = 0 for b in B: a = binary_search_meguru(A, b, is_ok1) c = binary_search_meguru(C, b, is_ok2) ans += a * (N-c) print(ans) if __name__ == '__main__': main()
p03557
def I(): return int(eval(input())) def LI(): return list(map(int,input().split())) def MI(): return list(map(int,input().split())) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] def isOK(index,key,li): if li[index] >= key: #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、 #ここの不等号にイコールを入れると #okはliの中でkey未満の数字がいくつあるかを表すようになる return True else: return False def binary_search(key,li): ng = -1 ok = len(li) while abs(ok - ng) > 1: mid = ok + ng //2 if isOK(mid,key,li): ok = mid else: ng = mid return ok #liはsortしておくことに注意 def isOK2(index,key,li): if li[index] > key: #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、 #ここの不等号にイコールを入れると #okはliの中でkey未満の数字がいくつあるかを表すようになる return True else: return False def binary_search2(key,li): ng = -1 ok = len(li) while abs(ok - ng) > 1: mid = ok + ng //2 if isOK2(mid,key,li): ok = mid else: ng = mid return ok #liはsortしておくことに注意 n = I() a_li = sorted(LI()) b_li = sorted(LI()) c_li= sorted(LI()) ans = 0 for i in range(n): B = b_li[i] k = n - binary_search2(B,c_li) l = binary_search(B,a_li) ans += k*l print(ans)
import bisect def I(): return int(eval(input())) def LI(): return list(map(int,input().split())) def MI(): return list(map(int,input().split())) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] #bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す #bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す #これを応用することで #len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す #len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す #これらを使うときはあらかじめlistをソートしておくこと! n = I() a_li = sorted(LI()) b_li = sorted(LI()) c_li= sorted(LI()) ans = 0 for i in range(n): B = b_li[i] k = n - bisect.bisect_right(c_li,B) l = bisect.bisect_left(a_li,B) ans += k*l print(ans)
p03557
import bisect n=int(eval(input())) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] c=[int(i) for i in input().split()] a.sort() b.sort() c.sort() s=bisect.bisect_left(a,b[-1]) l=bisect.bisect_right(c,b[0]) cnt=0 ab=[] for B in b: for A in a[:s+1]: if B>A: ab+=[B] ans=0 for AB in ab: for C in c[l:]: if AB<C: ans+=1 print(ans)
import bisect n=int(eval(input())) a=sorted([int(i) for i in input().split()]) b=sorted([int(i) for i in input().split()]) c=sorted([int(i) for i in input().split()]) ans=0 for B in b: m=bisect.bisect_left(a,B) l=bisect.bisect_right(c,B) ans+=m*(n-l) print(ans)
p03557
n = int(eval(input())) ai = [] bi = [] ci = [] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) for i in range(0,n): cnt = 0 for j in range(0,n): if a[i] >= b[j]: break cnt += 1 ai.append(cnt) for i in range(0,n): cnt = 0 for j in range(0,n): if b[i] >= c[j]: break cnt += 1 bi.append(cnt) ans = 0 for i in range(0,n): if ai[i] > 0: for j in range(0,ai[i]): ans += bi[j] print(ans)
n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) bmul = [0]*(n+1) ci = 0 for bi in range(n): while ci != n and c[ci] <= b[bi]: ci += 1 bmul[bi] = n-ci for i in range(n): bmul[n-i-1] += bmul[n-i] bi = 0 ai = 0 ret = 0 for ai in range(n): while bi != n and b[bi] <= a[ai]: bi += 1 ret += bmul[bi] print(ret)
p03557
#ABC077-C N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) ans=0 for i in range(N): b=B[i] if A[-1]<b: a_comb=N elif A[0]>=b: a_comb=0 elif A[0]<b and A[1]>=b: a_comb=1 else: p=N//2 while True: if A[p]<b and A[p+1]>=b: a_comb=p+1 break elif A[p]<b and A[p+1]<b: p=(N+p)//2 continue elif A[p]>=b: p=(p+1)//2 continue if C[0]>b: c_comb=N elif C[-1]<=b: c_comb=0 elif C[-1]>b and C[-2]<=b: c_comb=1 else: p=N//2 while True: if C[p]>b and C[p-1]<=b: c_comb=N-p break elif C[p]>b and C[p-1]>b: p=(p+1)//2 continue elif C[p]<=b: p=(N+p)//2 continue ans+=a_comb*c_comb print(ans)
#ABC077-C N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) ans=0 for i in range(N): b=B[i] left=0 right=N-1 if A[-1]<b: a_comb=N elif A[0]>=b: a_comb=0 elif A[0]<b and A[1]>=b: a_comb=1 else: a_comb=0 while left<=right: mid=(left+right)//2 if A[mid]<b and A[mid+1]>=b: a_comb=mid+1 break elif A[mid]<b and A[mid+1]<b: left=mid+1 elif A[mid]>=b: right=mid-1 left=0 right=N-1 if C[0]>b: c_comb=N elif C[-1]<=b: c_comb=0 elif C[-1]>b and C[-2]<=b: c_comb=1 else: c_comb=0 while left<=right: mid=(left+right)//2 if C[mid]>b and C[mid-1]<=b: c_comb=N-mid break elif C[mid]>b and C[mid-1]>b: right=mid-1 elif C[mid]<=b: left=mid+1 ans+=a_comb*c_comb print(ans)
p03557
# -*- coding: utf-8 -*- import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() Ac, Cc = [0]*n, [0]*n Ap, Cp = 0, 0 for i in range(n): index = bisect.bisect_left(A[Ap:], B[i]) Ac[i], Ap = index + Ap, index + Ap index = bisect.bisect_right(C[Cp:], B[i]) Cc[i], Cp = n - index - Cp, index + Cp count = 0 for i in range(n): count += Ac[i]*Cc[i] print(count)
# -*- coding: utf-8 -*- import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() Ac, Cc = [0]*n, [0]*n # Ap, Cp = 0, 0 for i in range(n): Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i]) # Ac[i], Ap = index + Ap, index + Ap Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i]) # Cc[i], Cp = n - index - Cp, index + Cp count = 0 for i in range(n): count += Ac[i]*Cc[i] print(count)
p03557
# -*- coding: utf-8 -*- import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() Ac, Cc = [0]*n, [0]*n # Ap, Cp = 0, 0 for i in range(n): Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i]) # Ac[i], Ap = index + Ap, index + Ap Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i]) # Cc[i], Cp = n - index - Cp, index + Cp count = 0 for i in range(n): count += Ac[i]*Cc[i] print(count)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) print((sum([bisect.bisect_left(A, b) * (N - bisect.bisect(C, b)) for b in B])))
p03557
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort() B = list(map(int, input().split())) B.sort() C = list(map(int, input().split())) C.sort() count = [0]*N answer = 0 z = 0 for i in range(N): if B[0] >= C[N-i-1]: break z += 1 count[0] = z for i in range(1, N): x = z for j in range(z): if B[i] < C[N-z+j]: break else: x -= 1 count[i] = x y = 0 for i in range(N): if A[0] >= B[N-i-1]: break answer += count[N-i-1] y += 1 for i in range(1, N): for j in range(y): if A[i] >= B[N-j-1]: break answer += count[N-j-1] #print(count) print(answer)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) count = [0]*N answer = 0 z = 0 for i in range(N): if B[N-1] >= C[i]: break z += 1 count[N-1] = z for i in range(1, N): k=z for j in range(k): if B[N-1-i] < C[k-1-j]: break else: z -= 1 count[N-1-i] = z sum_matrix = [0]*(N+1) y = 0 for i in range(N): sum_matrix[i+1] = sum_matrix[i] + count[i] for i in range(N): if A[N-1] >= B[i]: break answer += count[i] y += 1 for i in range(1, N): x = y for j in range(x): if A[N-1-i] < B[x-1-j]: break y -= 1 answer += sum_matrix[y] print(answer)
p03557
import bisect n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=list(map(int,input().split())) C=sorted(list(map(int,input().split()))) lb,lc=len(B),len(C) ans=0 for b in range(lb): ma = bisect.bisect_left(A, B[b]) mc = lc-bisect.bisect_right(C, B[b]) ans += ma*mc print(ans)
import bisect n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=list(map(int,input().split())) C=sorted(list(map(int,input().split()))) lc=len(C) ans=0 for b in B: ma = bisect.bisect_left(A, b) mc = lc-bisect.bisect_right(C, b) ans += ma*mc print(ans)
p03557
import bisect def main(): n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=list(map(int,input().split())) C=sorted(list(map(int,input().split()))) lc=len(C) ans=0 for b in B: ma = bisect.bisect_left(A, b) mc = lc-bisect.bisect_right(C, b) ans += ma*mc print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left, bisect_right input = sys.stdin.readline def main(): n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=list(map(int,input().split())) C=sorted(list(map(int,input().split()))) lc=len(C) ans=0 for b in B: ma = bisect_left(A, b) mc = lc-bisect_right(C, b) ans += ma*mc print(ans) if __name__ == "__main__": main()
p03557
import bisect n=eval(input()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for B in b: ans+=(bisect.bisect_left(a,B))*(len(c)-(bisect.bisect_right(c,B))) print(ans)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: A=bisect.bisect_left(a,i) C=bisect.bisect(c,i) ans+=A*(n-C) print(ans)
p03557
import bisect N = int(eval(input())) Alist = [int(x) for x in input().split()] Blist = [int(x) for x in input().split()] Clist = [int(x) for x in input().split()] Alist.sort() Blist.sort() Clist.sort() cache = [] result = 0 doneb = 0 donea = 0 for c in Clist: idxc = bisect.bisect_left(Blist, c) for i in range(0, idxc): b = Blist[i] idxb = bisect.bisect_left(Alist, b) result += idxb print(result)
import bisect N = int(eval(input())) Alist = [int(x) for x in input().split()] Blist = [int(x) for x in input().split()] Clist = [int(x) for x in input().split()] Alist.sort() Blist.sort() Clist.sort() result = 0 for b in Blist: a = bisect.bisect_left(Alist, b) c = N - bisect.bisect_right(Clist, b) result += a*c print(result)
p03557
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() ans = 0 for up in a: tmp1 = bisect.bisect_right(b, up) for middle in b[tmp1:]: down = bisect.bisect_right(c, middle) ans += (n - down) print(ans)
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() ans = 0 for middle in b: tmp1 = bisect.bisect_left(a, middle) tmp2 = bisect.bisect_right(c, middle) ans += tmp1 * (n - tmp2) print(ans)
p03557
import bisect n = int(eval(input())) a_li = list(map(int, input().split())) b_li = list(map(int, input().split())) c_li = list(map(int, input().split())) b_li.sort() c_li.sort() check_li = [0]*(n+10) for i in range(len(b_li)): s = bisect.bisect_right(c_li, b_li[i]) check_li[i] = len(c_li[s:]) tmp = 0 for i in range(1, n+11): check_li[-i] = check_li[-i] + tmp tmp = check_li[-i] ans = 0 for i in a_li: s = bisect.bisect_right(b_li, i) ans += check_li[s] print(ans)
import bisect n = int(eval(input())) a_li = list(map(int, input().split())) b_li = list(map(int, input().split())) c_li = list(map(int, input().split())) a_li.sort() b_li.sort() c_li.sort() ans = 0 for i in b_li: s = bisect.bisect_right(c_li, i) s_num = n-s t = bisect.bisect_left(a_li, i) t_num = t ans += s_num * t_num print(ans)
p03557
n = int(eval(input())) A_list = list(map(int, input().split())) B_list = list(map(int, input().split())) C_list = list(map(int, input().split())) A_list = sorted(A_list) B_list = sorted(B_list) C_list = sorted(C_list) cnt = 0 def is_ok(arg): return B_list[arg] > A_list[i] def bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok def is_ok2(arg): return C_list[arg] > B_list[j] def bisect2(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok2(mid): ok = mid else: ng = mid return ok for i in range(n): #Aを決定 #Aより大きいBを探す B_key = bisect(-1, len(B_list)-1) if A_list[i] < B_list[B_key]: for j in range(B_key, n): #Bより大きいCを探す C_key = bisect2(-1, len(C_list)-1) if B_list[j] < C_list[C_key]: cnt += n-C_key else: break else: break print(cnt)
n = int(eval(input())) A_list = list(map(int, input().split())) B_list = list(map(int, input().split())) C_list = list(map(int, input().split())) A_list = sorted(A_list) B_list = sorted(B_list) C_list = sorted(C_list) cnt = 0 def is_ok(arg): # B より小さい最大の A return A_list[arg] < B_list[i] def bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok def is_ok2(arg): # B より大きい最小の A return C_list[arg] > B_list[i] def bisect2(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok2(mid): ok = mid else: ng = mid return ok for i in range(n): #Bを固定 #Bより小さいAを探す A_key = bisect(len(A_list), 0) if A_list[A_key] < B_list[i]: #Bより大きいCを探す C_key = bisect2(-1, len(C_list)-1) if B_list[i] < C_list[C_key]: #print(A_key, i, C_key, A_list[A_key], B_list[i], C_list[C_key]) cnt += (n-C_key)*(A_key+1) print(cnt)
p03557
def main(): N = int(eval(input())) A = list(map(int, input().split())) B = sorted(list(map(int, input().split())), reverse=True) C = sorted(list(map(int, input().split()))) ans = 0 for a in A: for b in B: if a >= b: break for i, c in enumerate(C): if c > b: ans += N - i break print(ans) main()
import bisect def main(): N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(ans) main()
p03557
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() bi = [n for _ in range(n)] for i in range(n): for j in range(n): if b[i] <= a[j]: bi[i] = j break ans = 0 for i in range(n): for j in range(n): if c[i] <= b[j]: break else: ans += bi[j] print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0; for bj in b: ai = bisect.bisect_left(a, bj); ck = n - bisect.bisect_right(c, bj); ans += ai * ck; print(ans)
p03557
from bisect import bisect_left from collections import defaultdict N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 dict_C = defaultdict(int) for b in B: dict_C[b] = C.count(b) for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_left(C, b) num_c = N - pre_num_c # c > b となるAの要素数 if pre_num_c != N and C[pre_num_c] == b: num_c -= dict_C[b] res += num_a * num_c pre_b = b print(res)
from bisect import bisect_left from collections import defaultdict N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 dict_C = defaultdict(int) for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_left(C, b) num_c = N - pre_num_c # c > b となるAの要素数 if pre_num_c != N and C[pre_num_c] == b: num_c = N - bisect_left(C, b+1) res += num_a * num_c pre_b = b print(res)
p03557
from bisect import bisect_left from collections import defaultdict N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 dict_C = defaultdict(int) for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_left(C, b) num_c = N - pre_num_c # c > b となるAの要素数 if pre_num_c != N and C[pre_num_c] == b: num_c = N - bisect_left(C, b+1) res += num_a * num_c pre_b = b print(res)
from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_right(C, b) num_c = N - pre_num_c # c > b となるAの要素数 res += num_a * num_c pre_b = b print(res)
p03557
# abc077_c.py ''' 多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。 ''' def is_okC(idx,key,target): ########## wirte criteria here ########## if target[idx] > key: return True return False def meguru_bisectC(key,target): left = -1 right = len(target) while (abs(right - left) > 1): mid = left + (right - left) // 2 if is_okC(mid,key,target): right = mid else: left = mid # print("C : ",target[right:]) return target[right:] def is_okA(idx,key,target): ########## wirte criteria here ########## if target[idx] >= key: return True return False def meguru_bisectA(key,target): left = -1 right = len(target) while (abs(right - left) > 1): mid = left + (right - left) // 2 # print("mid : " , mid) if is_okA(mid,key,target): right = mid else: left = mid # print("A : ",target[:right]) return target[:right] N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() C.sort() a = 0 c = 0 ans = 0 for i in B: a = len(meguru_bisectA(i,A)) # print("i : ",i) c = len(meguru_bisectC(i,C)) ans += a*c # print() print(ans)
# abc077_c.py ''' 多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。 ''' def is_okC(idx,key,target): ########## wirte criteria here ########## if target[idx] > key: return True return False def meguru_bisectC(key,target): left = -1 length = len(target) right = length while (abs(right - left) > 1): mid = left + (right - left) // 2 if is_okC(mid,key,target): right = mid else: left = mid return length-right def is_okA(idx,key,target): ########## wirte criteria here ########## if target[idx] >= key: return True return False def meguru_bisectA(key,target): left = -1 length = len(target) right = length while (abs(right - left) > 1): mid = left + (right - left) // 2 # print("mid : " , mid) if is_okA(mid,key,target): right = mid else: left = mid return right N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() C.sort() a = 0 c = 0 ans = 0 #print(A) #print(B) #print(C) for i in B: a = meguru_bisectA(i,A) # print(A[:a] ) # print("i : ",i) c = meguru_bisectC(i,C) # print(C[c:]) ans += a*c # print() print(ans)
p03557
def bisect(lst, isok, ok, ng): while(abs(ok-ng)>1): mid = (ok+ng)//2 if isok(lst[mid]): ok = mid else: ng = mid return [ok, ng] n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort() b.sort() c.sort() ans = 0 for i in a: ind = bisect(b, lambda x:x > i, n, -1)[0] if ind == n: break for j in range(ind, n): ans += n - bisect(c, lambda x:x > b[j], n, -1)[0] print(ans)
def bisect(lst, isok, ok, ng): while(abs(ok-ng)>1): mid = (ok+ng)//2 if isok(lst[mid]): ok = mid else: ng = mid return [ok, ng] n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort() b.sort() c.sort() ans = 0 for i in b: x = bisect(a, lambda x:x < i, -1, n)[0] y = bisect(c, lambda x:x > i, n, -1)[0] ans += (x+1)*(n-y) print(ans)
p03557
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(len(C)): b = bisect.bisect_left(B,C[i]) if b == 0: continue for j in range(b): a = bisect.bisect_left(A,B[j]) ans += a print(ans)
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for b in B: a = bisect.bisect_left(A,b) c = n - bisect.bisect_left(C,b+1) ans += a*c print(ans)
p03557
#!/usr/bin/env python3 import sys from bisect import bisect_right def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"): ans = 0 A.sort() B.sort() C.sort() for i in range(N): bi = bisect_right(B, A[i]) for j in range(bi, N): ci = bisect_right(C, B[j]) ans += N-ci print(ans) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" B = [int(next(tokens)) for _ in range(N)] # type: "List[int]" C = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A, B, C) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys from bisect import bisect_right, bisect_left def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"): ans = 0 A.sort() B.sort() C.sort() for i in range(N): ai = bisect_left(A, B[i]) ci = bisect_right(C, B[i]) ans += (ai) * (N-ci) print(ans) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" B = [int(next(tokens)) for _ in range(N)] # type: "List[int]" C = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A, B, C) if __name__ == '__main__': main()
p03557
import bisect N=int(eval(input())) A=[int(x) for x in input().split()] B=[int(x) for x in input().split()] C=[int(x) for x in input().split()] A.sort() B.sort() C.sort() ans=0 for i in range(N): a=bisect.bisect_right(C,B[i]) b=bisect.bisect_left(A,B[i]) ans+=(N-a)*b print(ans)
import bisect N=int(eval(input())) A=[int(x) for x in input().split()] B=[int(x) for x in input().split()] C=[int(x) for x in input().split()] A.sort() B.sort() C.sort() ans=0 for i in range(N): ans+=(bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))) print(ans)
p03557
from collections import Counter import bisect N=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) a_raw=Counter(A) b_raw=Counter(B) c_raw=Counter(C) a=sorted(list(a_raw.items()), key=lambda x: x[0]) c=sorted(list(c_raw.items()), key=lambda x: x[0]) ans=0 for i in b_raw: insert_index_a = bisect.bisect_left([a[x][0] for x in range(len(a))],i) insert_index_c = bisect.bisect_right([c[y][0] for y in range(len(c))],i) if insert_index_a>0 and insert_index_c !=len(c): sum_a=sum(a[m][1] for m in range(insert_index_a)) sum_c=sum(c[n][1] for n in range(insert_index_c,len(c))) ans+=sum_a * b_raw[i] * sum_c print(ans)
import bisect N=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for i in B: ins_a = bisect.bisect_left(A,i) ins_c = bisect.bisect_right(C,i) ans+=ins_a*(N-ins_c) print(ans)
p03557
# coding:utf-8 import sys import math import time #import numpy as np import collections from collections import deque from collections import Counter import queue import copy import bisect import heapq def dfs(s, prev, pre): val[s] += Ope[s] + prev for i in G[s]: if(i == pre): continue dfs(i, val[s], s) def bfs(sx, sy, n): que = deque([[sy,sx]]) while que: y,x = que.popleft() for i,j in D: if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1): continue dist = G[y+j][x+i] if(G[y+j][x+i] != "X"): if(type(G[y+j][x+i]) is str): G[y+j][x+i] = G[y][x]+1 que.append([y+j,x+i]) elif(dist>G[y][x]+1): G[y+j][x+i] = G[y][x]+1 que.append([y+j,x+i]) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) #sys.setrecursionlimit(10**7) #N, Q = map(int, input().split()) #G = [list(input()) for i in range(H)] #INF = V * 10001 #A = [int(i) for i in input().split()] #AB = [list(map(int, input().split())) for _ in range(K)] N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] ans = 0 A.sort() B.sort() C.sort() for i in range(N): temp = bisect.bisect_left(B, A[i]+1) for j in range(temp, N): ans += (N-bisect.bisect_left(C, B[j]+1)) print(ans)
# coding:utf-8 import sys import math import time #import numpy as np import collections from collections import deque from collections import Counter import queue import copy import bisect import heapq def dfs(s, prev, pre): val[s] += Ope[s] + prev for i in G[s]: if(i == pre): continue dfs(i, val[s], s) def bfs(sx, sy, n): que = deque([[sy,sx]]) while que: y,x = que.popleft() for i,j in D: if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1): continue dist = G[y+j][x+i] if(G[y+j][x+i] != "X"): if(type(G[y+j][x+i]) is str): G[y+j][x+i] = G[y][x]+1 que.append([y+j,x+i]) elif(dist>G[y][x]+1): G[y+j][x+i] = G[y][x]+1 que.append([y+j,x+i]) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) #sys.setrecursionlimit(10**7) #N, Q = map(int, input().split()) #G = [list(input()) for i in range(H)] #INF = V * 10001 #A = [int(i) for i in input().split()] #AB = [list(map(int, input().split())) for _ in range(K)] N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] AA = [0]*N BB = [0]*N ans = 0 A.sort() B.sort() C.sort() for i in range(N): AA[i] = bisect.bisect_right(A, B[i]-1) for j in range(N): BB[j] = bisect.bisect_left(C, B[j]+1) for k in range(N): ans += AA[k]*(N-BB[k]) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() lb = [0] * len(B) for i in range(len(B)): lb[i]= bisect.bisect_left(A,B[i]) ans = 0 for i in range(len(C)): temp = bisect.bisect_left(B,C[i]) ans +=sum(lb[0:temp]) print(ans)
import bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() lb = [0] * (len(B)+1) lsum = [0] * (len(B)+1) temp = 0 for i in range(len(B)): lb[i]= bisect.bisect_left(A,B[i]) for i in range(len(B)): lsum[i] = lb[i] +lsum[i-1] ans = 0 for i in range(len(C)): temp = bisect.bisect_left(B,C[i]) ans +=lsum[temp-1] print(ans)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() b_bt = [] c_bt = [] for i in range(n): b_bt.append(bisect.bisect_left(a, b[i])) c_bt.append(bisect.bisect_left(b, c[i])-1) result = 0 for i in range(n): if c_bt[i] >= 0: result += sum(b_bt[:c_bt[i]+1]) print(result)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() result = 0 for i in range(n): x = bisect.bisect_left(a, b[i]) y = n - bisect.bisect_right(c, b[i]) result += x*y print(result)
p03557
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) return N, A, B, C def binary_search(l: list, key: int) -> int: """ l[index] > keyとなる最小のindexを求める. Args:\n l (list): リスト key (int): 整数 Returns:\n int: l[index] > keyとなる最小のindex """ low = -1 high = len(l) while 1 < high - low: mid = (low + high) // 2 guess = l[mid] if guess > key: high = mid else: low = mid return high def main(N: int, A: list, B: list, C: list) -> None: """ メイン処理. Args:\n N (int): パーツの数 A (list): 上部のパーツのサイズ B (list): 中部のパーツのサイズ C (list): 下部のパーツのサイズ """ # 事前にリストをソートしておく A = sorted(A) B = sorted(B) C = sorted(C) # 求解処理 ans = 0 for i in range(N): A_i = A[i] lb_B = binary_search(B, A_i) for j in range(lb_B, N): B_j = B[j] lb_C = binary_search(C, B_j) ans += N - lb_C # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, A, B, C = get_input() # メイン処理 main(N, A, B, C)
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) return N, A, B, C def get_lb(l: list, key: int) -> int: """ l[index] > keyとなる最小のindexを求める. Args:\n l (list): リスト key (int): 整数 Returns:\n int: l[index] > keyとなる最小のindex """ low = -1 high = len(l) while 1 < high - low: mid = (low + high) // 2 guess = l[mid] if guess > key: high = mid else: low = mid return high def get_ub(l: list, key: int) -> int: """ l[index] < keyとなる最大のindexを求める. Args:\n l (list): リスト key (int): 整数 Returns:\n int: l[index] < keyとなる最大のindex """ low = -1 high = len(l) while 1 < high - low: mid = (low + high) // 2 guess = l[mid] if guess < key: low = mid else: high = mid return low def main(N: int, A: list, B: list, C: list) -> None: """ メイン処理. Args:\n N (int): パーツの数 A (list): 上部のパーツのサイズ B (list): 中部のパーツのサイズ C (list): 下部のパーツのサイズ """ # 事前にリストをソートしておく A = sorted(A) B = sorted(B) C = sorted(C) # 求解処理 ans = 0 for i in range(N): B_i = B[i] ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i)) # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, A, B, C = get_input() # メイン処理 main(N, A, B, C)
p03557
# -*- coding: utf-8 -*- # モジュールのインポート import itertools # 標準入力を取得 N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # 求解処理 def get_ub(l: list, x: int) -> int: low = -1 high = len(l) while 1 < high - low: mid = (high + low) // 2 guess = l[mid] if guess > x: high = mid else: low = mid return high C = sorted(C) ans = 0 for A_i, B_i in itertools.product(A, B): if A_i >= B_i: continue ans += N - get_ub(C, B_i) # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) return N, A, B, C def get_lb(l: list, key: int) -> int: """ l[index] > keyとなる最小のindexを求める. Args:\n l (list): リスト key (int): 整数 Returns:\n int: l[index] > keyとなる最小のindex """ low = -1 high = len(l) while 1 < high - low: mid = (low + high) // 2 guess = l[mid] if guess > key: high = mid else: low = mid return high def get_ub(l: list, key: int) -> int: """ l[index] < keyとなる最大のindexを求める. Args:\n l (list): リスト key (int): 整数 Returns:\n int: l[index] < keyとなる最大のindex """ low = -1 high = len(l) while 1 < high - low: mid = (low + high) // 2 guess = l[mid] if guess < key: low = mid else: high = mid return low def main(N: int, A: list, B: list, C: list) -> None: """ メイン処理. Args:\n N (int): パーツの数(1 <= N <= 10**5) A (list): 上部のパーツのサイズ(1 <= A_i <= 10**9) B (list): 中部のパーツのサイズ(1 <= B_i <= 10**9) C (list): 下部のパーツのサイズ(1 <= C_i <= 10**9) """ # 事前にリストをソートしておく A = sorted(A) B = sorted(B) C = sorted(C) # 求解処理 ans = 0 for i in range(N): B_i = B[i] ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i)) # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, A, B, C = get_input() # メイン処理 main(N, A, B, C)
p03557
def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) import bisect N = INT() A = LIST() B = LIST() C = LIST() A.sort() B.sort() C.sort() ans = 0 # for ai in A: # i = bisect.bisect_right(B, ai) # for bi in B[i:]: # j = bisect.bisect_right(C, bi) # ans += len(C[j:]) for bi in B: i = bisect.bisect_left(A, bi) j = bisect.bisect_right(C, bi) ans += len(A[:i]) * len(C[j:]) print(ans)
def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) # import bisect N = INT() A = LIST() B = LIST() C = LIST() A.sort() B.sort() C.sort() def binsearch(lst, th, ud="up"): left, right = -1, len(lst) while right - left > 1: mid = (left + right) // 2 if ud == "up": if lst[mid] > th: right = mid else: left = mid else: if lst[mid] >= th: right = mid else: left = mid return right if ud == "up" else left ans = 0 # for ai in A: # i = bisect.bisect_right(B, ai) # for bi in B[i:]: # j = bisect.bisect_right(C, bi) # ans += len(C[j:]) for bi in B: i = binsearch(A, bi, "down") j = binsearch(C, bi, "up") ans += (i+1) * (N-j) print(ans)
p03557
import bisect, functools, sys sys.setrecursionlimit(10**6) N = int(eval(input())) A = sorted(int(x) for x in input().split()) B = sorted(int(x) for x in input().split()) C = sorted(int(x) for x in input().split()) @functools.lru_cache(maxsize=None) def a(n): return bisect.bisect_left(A, n) b_cache = [0] * (N + 1) b_cached = [False] * (N + 1) def b_i(i): global b_cache, b_cached if i >= 1: if not b_cached[i - 1]: b_i(i - 1) t = b_cache[i - 1] + a(B[i - 1]) b_cache[i] = t b_cached[i] = True return t return 0 @functools.lru_cache(maxsize=None) def b(n): return b_i(min(N, bisect.bisect_left(B, n))) def c(): return sum(b(x) for x in C) print((c()))
N = int(eval(input())) A = sorted(int(x) for x in input().split()) B = sorted(int(x) for x in input().split()) C = sorted(int(x) for x in input().split()) import bisect print((sum(bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) for b in B)))
p03557
import bisect def main(): N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) counter = 0 for c in C: b_count = bisect.bisect_left(B, c) for b in B[0:b_count]: a_count = bisect.bisect_left(A, b) counter += a_count print(counter) if __name__ == "__main__": main()
import bisect def main(): N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) counter = 0 for b in B: a_count = bisect.bisect_left(A, b) c_count = N - bisect.bisect_right(C, b) counter += a_count*c_count print(counter) if __name__ == "__main__": main()
p03557
import math import sys import queue import copy import bisect#2分探索 def input(): return sys.stdin.readline()[:-1] def inputi(): return int(input()) def inputl(): return list(map(int, input().split())) def printl(li): print(*li, sep="\n") def argsort(s): return sorted(range(len(s)), key=lambda k: s[k]) #mod = 10**9+7 N = inputi() #N, K = inputl() #L = [int(input()) for i in range(N)] A = inputl() B = inputl() C = inputl() #S = [inputl() for i in range(H)] #q = queue.Queue() #q.put(i) #q.get() #q = queue.LifoQueue() #q.put(i) #q.get() #a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ #b=copy.deepcopy(a) #2次元配列はこうコピーする #w.sort(key=lambda x:x[1],reverse=True) #二個目の要素で降順並び替え #素数リスト # n = 100 # primes = set(range(2, n+1)) # for i in range(2, int(n**0.5+1)): # primes.difference_update(range(i*2, n+1, i)) # primes=list(primes) #bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。 #bisect.insort_left(a, 4)#挿入 A.sort(reverse=True) B.sort() C.sort() tot=0 cut=N for a in A: cut=bisect.bisect_right(B[0:cut], a) cut2=N for i in reversed(range(cut,N)): b=B[i] cut2=bisect.bisect_right(C[0:cut2], b) tot+=N-cut2 print(tot)
import sys #import math #import queue #import copy import bisect#2分探索 def input(): return sys.stdin.readline()[:-1] def inputi(): return int(input()) def inputl(): return list(map(int, input().split())) def printl(li): print(*li, sep="\n") def argsort(s): return sorted(range(len(s)), key=lambda k: s[k]) #mod = 10**9+7 N = inputi() #N, K = inputl() #L = [int(input()) for i in range(N)] A = inputl() B = inputl() C = inputl() #S = [inputl() for i in range(H)] #q = queue.Queue() #q.put(i) #q.get() #q = queue.LifoQueue() #q.put(i) #q.get() #a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ #b=copy.deepcopy(a) #2次元配列はこうコピーする #w.sort(key=lambda x:x[1],reverse=True) #二個目の要素で降順並び替え #素数リスト # n = 100 # primes = set(range(2, n+1)) # for i in range(2, int(n**0.5+1)): # primes.difference_update(range(i*2, n+1, i)) # primes=list(primes) #bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。 #bisect.insort_left(a, 4)#挿入 ##TLE # A.sort(reverse=True) # B.sort() # C.sort() # tot=0 # cut=N # for a in A: # cut=bisect.bisect_right(B[0:cut], a) # cut2=N # for i in reversed(range(cut,N)): # b=B[i] # cut2=bisect.bisect_right(C[0:cut2], b) # tot+=N-cut2 #right ans tot=0 A.sort() C.sort() for b in B: cut1=bisect.bisect_left(A, b) cut2=bisect.bisect_right(C, b) tot+=cut1*(N-cut2) print(tot)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(N): for j in range(N): if A[i] < B[j]: for k in range(N): if B[j] < C[N-1-k]: ans += 1 else: break print(ans)
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(N): a = bisect.bisect_left(A, B[i]) c = bisect.bisect_right(C, B[i]) ans += a*(N-c) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(N): a = bisect.bisect_left(A, B[i]) c = bisect.bisect_right(C, B[i]) ans += a*(N-c) print(ans)
from bisect import * n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(n): ans += bisect_left(a, b[i])*(n-bisect_right(c, b[i])) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() a2=[] for i1 in range(N): a2.append(bisect.bisect_left(C,B[i1]+1)) ans=0 for i0 in range(N): a1 = bisect.bisect_left(B,A[i0]+1) for i1 in range(a1,N): ans += N - a2[i1] print(ans)
import bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() a2=[] for i1 in range(N): a2.append(bisect.bisect_left(C,B[i1]+1)) a2c=[0]*(N+1) for i1 in range(N-1,-1,-1): a2c[i1] = a2c[i1+1] + N - a2[i1] ans=0 for i0 in range(N): a1 = bisect.bisect_left(B,A[i0]+1) ans += a2c[a1] print(ans)
p03557
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc077_c(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() B.sort() C.sort() ans = 0 # 二分探索で Ai < Bj < Ck となる個数を数える from bisect import bisect_left for i in range(N): # 真に大きいが条件なので Ai + 1 が入るポイントを探す jst = bisect_left(B, A[i] + 1) if jst == N: continue for j in range(jst, N): kst = bisect_left(C, B[j] + 1) ans += N - kst print(ans) abc077_c()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc077_c(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() B.sort() C.sort() ans = 0 from bisect import bisect_left # Bjに対するCの使える個数は、前処理で求めておく B2C = [0] * N # 真に大きいが条件なので Ai + 1 が入るポイントを探す for j in range(N): B2C[j] = N - bisect_left(C, B[j]+1) # 累積和 accum = [0] for j in range(N): accum.append(accum[-1] + B2C[j]) # Ai -> B は二分探索 for i in range(N): jst = bisect_left(B, A[i]+1) if jst == N: continue # 前処理済みなので、Bj以降を使ったときにCが何個使えるかはすぐわかる ans += accum[N] - accum[jst] print(ans) abc077_c()
p03557
N = int(eval(input())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) c_list = list(map(int, input().split())) a_list.sort() c_list.sort() result = 0 for b in b_list: a_count = list([x for x in a_list if x < b]) c_count = list([x for x in c_list if x >b]) result += len(a_count)*len(c_count) print(result)
import bisect N = int(eval(input())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) c_list = list(map(int, input().split())) a_list.sort() c_list.sort() result = 0 for b in b_list: a_count = bisect.bisect_left(a_list, b) c_count = bisect.bisect_right(c_list, b) result += a_count*(len(c_list)-c_count) print(result)
p03557
import sys import bisect input = sys.stdin.readline def slove(): n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A = sorted(A) B = sorted(B) C = sorted(C) ans = 0 for i in range(n): k = bisect.bisect(B,A[i]) for j in range(k,n): l = bisect.bisect(C,B[j]) ans += n-l return ans if __name__ == "__main__": print((slove()))
import sys import bisect input = sys.stdin.readline def slove(): n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A = sorted(A) B = sorted(B) C = sorted(C) ans = 0 for i in range(n): k = B[i] a = bisect.bisect_left(A,k) c = n-bisect.bisect_right(C,k) ans += a*c return ans if __name__ == "__main__": print((slove()))
p03557
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 for second in B: idx = bisect.bisect_left(A, second) first = len(A[:idx]) idx = bisect.bisect_right(C, second) third = len(C[idx:]) ans += (first*third) print(ans)
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 for second in B: ai = bisect.bisect_left(A, second) ci = bisect.bisect_right(C, second) ans += (ai*(N-ci)) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for b in B: a = bisect.bisect_left(A, b) # 挿入点はどの同じ値よりも左 c = bisect.bisect_right(C, b) # 挿入点はどの同じ値よりも右 ans += a * (len(C)-c) print (ans)
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() ans=0 for i in range(n): A=bisect.bisect_left(a,b[i]) B=bisect.bisect_right(c,b[i]) ans=ans+A*(n-B) print(ans)
p03557
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() ans=0 for i in range(n): A=bisect.bisect_left(a,b[i]) B=bisect.bisect_right(c,b[i]) ans=ans+A*(n-B) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() import bisect ans=0 for i in b: q=bisect.bisect_left(a,i) s=bisect.bisect_right(c,i) ans=ans+q*(n-s) print(ans)
p03557
from collections import Counter N=int(eval(input())) A=Counter(input().split()) B=Counter(input().split()) C=Counter(input().split()) ans=0 for a_key,a_count in A.most_common(): for b_key,b_count in B.most_common(): for c_key,c_count in C.most_common(): a_key,b_key,c_key=int(a_key),int(b_key),int(c_key) if a_key<b_key and b_key<c_key: ans+=a_count*b_count*c_count print(ans)
import bisect N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) print((sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B)))
p03557
import bisect n=int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() ans = 0 for k in b: pos1 = bisect.bisect_left(a,k) pos2 = bisect.bisect_right(c,k) ans += (pos1*(n-pos2)) print(ans)
import bisect n=int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) ans = 0 for k in b: pos1 = bisect.bisect_left(a,k) pos2 = bisect.bisect_right(c,k) ans += (pos1*(n-pos2)) print(ans)
p03557
n = int(eval(input())) A, B, C = [list(map(int, input().split())) for _ in range(3)] cnt = 0 # O(3*N) でギリギリ?pythonだと微妙かも # 真ん中のやつを基準にして上のやつと下のやつを比べて # あるいはバイナリサーチ for b in B: a_cnt, c_cnt = 0, 0 for i in range(n): if A[i]<b: a_cnt+=1 if b<C[i]: c_cnt+=1 cnt += a_cnt*c_cnt print(cnt)
# バイナリサーチで解く。 # Bの要素を基準にしてa<b<cとなるものを選ぶ。すべての配列はソート済みとして、 # a<bとなる最大のa, b<cとなる最小のcを選び、それら独立する事象の数の積を足していく n = int(eval(input())) A, B, C = [list(sorted(map(int, input().split()))) for _ in range(3)] cnt = 0 def bs_left(lis, target): # ソート済みのlisのうちtargetがどこに入るか(index) # 要素がtargetと重複する場合はより小さいインデックスを返す。すなわち「lisのうちtarget未満となる最大の要素のインデックス」 # ex) min(lis)=mとするとtarget<=mのとき0 low, high = 0, len(lis) while low<high: mid = (low+high)//2 if lis[mid]<target: low = mid+1 else: high = mid return low def bs_right(lis, target): low, high = 0, len(lis) while low<high: mid = (low+high)//2 if target<lis[mid]: high = mid else: low = mid+1 return low for b in B: # 探索のときにちゃんとみているので a!=b and b!=cみたいな条件は必要ない cnt += (bs_left(A, b) * (n-bs_right(C, b))) print(cnt)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for ai in a: idx_b = bisect.bisect_right(b, ai) if idx_b == n: break for bi in b[idx_b:]: ans += n - bisect.bisect_right(c, bi) print(ans)
from itertools import accumulate import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 b_ = [] for bi in reversed(b): b_.append(n - bisect.bisect_right(c, bi)) b_ = list(accumulate(b_))[::-1] for ai in a: idx_b = bisect.bisect_right(b, ai) if idx_b == n: break ans += b_[idx_b] print(ans)
p03557
import sys import math N = int(eval(input())) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) array1 = list() for b in B: count = 0 for c in C: if b < c: count += 1 array1.append(count) ans = 0 for i in range(N): count = 0 for a in A: if B[i] > a: count += 1 ans += count * array1[i] print(ans)
import sys import math N = int(eval(input())) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) A.sort() B.sort() C.sort() array1 = list() count = 0 f = 0 for j in range(N): for i in range(f, N): if B[N-1-j] < C[N-1-i]: count += 1 if i == N-1: f = N else: f = i break array1.append(count) ans = 0 f = 0 count = 0 for i in range(N): for j in range(f, N): if B[i] > A[j]: count += 1 if j == N-1: f = N else: f = j break ans += count * array1[N-1-i] print(ans)
p03557
from bisect import bisect_left, bisect_right N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() C.sort() result = 0 for i in range(N): a = bisect_left(A,B[i]) c = bisect_right(C,B[i]) result += len(A[:a]) * len(C[c:]) print(result)
from bisect import bisect_left, bisect_right N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() C.sort() result = 0 for i in B: a = bisect_left(A,i) c = bisect_right(C,i) result += a * (N - c) print(result)
p03557
import bisect N=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] C=[int(i) for i in input().split()] A.sort() B.sort() C.sort() # print(A) # print(B) # print(C) # ans=0 # for i in range(N): # part1=A[i] # part2_pos=bisect.bisect_right(B,part1) # for j in range(part2_pos,N): # part2=B[j] # part3_pos=bisect.bisect_right(C,part2) # # print(i,j,part3_spos,": ",A[i],B[j],C[part3_pos]) # ans+=(N-part3_pos) # print(ans) AtoB_Pos=[] BtoC_Pos=[] ans=0 for i in range(N): B_Pos=bisect.bisect_right(B,A[i]) AtoB_Pos.append(B_Pos) for i in range(N): C_Pos=bisect.bisect_right(C,B[i]) BtoC_Pos.append(C_Pos) # print(AtoB_Pos) # print(BtoC_Pos) for i in range(N): for j in range(AtoB_Pos[i],N): # print(i,j,": ",A[i],B[j]) # print(N-AtoB_Pos[i],N-BtoC_Pos[j]) ans+=(N-BtoC_Pos[j]) print(ans)
import bisect N=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] C=[int(i) for i in input().split()] A.sort() B.sort() C.sort() # print(A) # print(B) # print(C) ans=0 for j in range(N): a_num=bisect.bisect_left(A,B[j]) c_num=bisect.bisect_right(C,B[j]) # print(B[j],A[:a_num],C[c_num:]) # print(a_num,c_num) ans+=a_num*(N-c_num) print(ans)
p03557
import bisect N=int(eval(input())) ue=list(map(int,input().split())) naka=list(map(int,input().split())) sita=list(map(int,input().split())) ue.sort(),sita.sort(),naka.sort() count=0 stop=[0]*N for i in range(N): k=naka[i] stop_index=bisect.bisect_right(sita,k) if stop_index!=N: stop[i]=N-stop_index for i in range(N): k=ue[i] a=bisect.bisect_right(naka,k) if a!=N: count+=sum(stop[a:N]) print(count)
import bisect N=int(eval(input())) ue=list(map(int,input().split())) naka=list(map(int,input().split())) sita=list(map(int,input().split())) sita.sort(),naka.sort(),ue.sort() count2=[0]*N count1=[0]*N for i in range(N): m = naka[i] k=naka[i] small=bisect.bisect_left(ue,k) count1[i]=small big = bisect.bisect_right(sita, m) count2[i]=N-big ans=0 for i in range(N): ans+=count1[i]*count2[i] print(ans)
p03557
def search(key, L): inc = -1 exc = N while abs(inc-exc) > 1: mid = (inc+exc) // 2 if True if L[mid] <= key else False: inc = mid else: exc = mid return exc def main(): ans = 0 for a in A: for i in range(search(a, B), N): ans += N - search(B[i], C) print(ans) if __name__ == "__main__": N = int(eval(input())) A = [int(a) for a in input().split()] B = sorted([int(b) for b in input().split()]) C = sorted([int(c) for c in input().split()]) main()
def search(key, L): inc = -1 exc = N while abs(inc-exc) > 1: mid = (inc+exc) // 2 if True if L[mid] <= key else False: inc = mid else: exc = mid return exc def main(): ans = 0 for a in A: e = search(a, B) if e < N: ans += E[e] print(ans) if __name__ == "__main__": N = int(eval(input())) A = [int(a) for a in input().split()] B = sorted([int(b) for b in input().split()]) C = sorted([int(c) for c in input().split()]) E = [0]*N for i in range(1, N+1): E[-i] = (N-search(B[N-i], C)) + E[-i+1] main()
p03557
import bisect N = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort() B.sort() C.sort() up_mid = [N - bisect.bisect_right(B, x) for x in A] mid_down = [N - bisect.bisect_right(C, x) for x in B] ans = 0 for i in up_mid: ans += sum(mid_down[::-1][:i]) print(ans)
import bisect N = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort() B.sort() C.sort() ans = 0 for b in B: ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(ans)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [] total = 0 for i in range(len(B)): count = 0 for j in range(len(A)): if A[j]<B[i]: count+=1 AB.append(count) for i in range(len(C)): for j in range(len(B)): if B[j]<C[i]: total+=AB[j] print(total)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() AB = [0]*N total = 0 for i in range(N): left = -1 right = N while right-left>1: mid = left + (right-left)//2 if A[mid]>=B[i]: right = mid else: left = mid AB[i]=right for i in range(1,N): AB[i]+=AB[i-1] for i in range(N): left = -1 right = N while right-left>1: mid = left + (right-left)//2 if B[mid]>=C[i]: right = mid else: left = mid if right!=0: total+=AB[right-1] print(total)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() AB = [0]*N total = 0 for i in range(N): left = -1 right = N while right-left>1: mid = left + (right-left)//2 if A[mid]>=B[i]: right = mid else: left = mid AB[i]=right for i in range(1,N): AB[i]+=AB[i-1] for i in range(N): left = -1 right = N while right-left>1: mid = left + (right-left)//2 if B[mid]>=C[i]: right = mid else: left = mid if right!=0: total+=AB[right-1] print(total)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() total = 0 for i in range(N): left = -1 right = N while right-left>1: mid = left + (right-left)//2 if A[mid]>=B[i]: right = mid else: left = mid left2 = -1 right2 = N while right2-left2>1: mid2 = left2 + (right2-left2)//2 if C[mid2]>B[i]: right2 = mid2 else: left2 = mid2 total+=right*(N-right2) print(total)
p03557
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) Bn = [0] * N prea = 0 for b in range(N): for a in range(prea, N): if A[a] < B[b]: prea = a break else: break Bn[b] = N-a ans = 0 preb = 0 for c in range(N): for b in range(preb, N): if B[b] < C[c]: preb = b break else: break ans += sum(Bn[b:]) print(ans)
import bisect N = int(eval(input())) A = list(map(int, input().split())) A.sort() B = list(map(int, input().split())) C = list(map(int, input().split())) C.sort() ans = 0 for i in range(N): cnta = bisect.bisect_left(A, B[i]) cntc = bisect.bisect_right(C, B[i]) ans += cnta * (N - cntc) print(ans)
p03557
def m(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) cnt = 0 for a in A: for b in B: for c in C: if a < b and b < c: cnt +=1 return cnt print((m()))
def someone_ans(): def binary_search(L, key, mode): low, high = 0, len(L) mid = len(L) // 2 while low <= high - 1: if L[mid] < key and mode == 0 or L[mid] <= key and mode == 1: low = mid + 1 else: high = mid mid = (low + high) // 2 return high N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for i in B: Ai = binary_search(A, i, 0) Ci = len(C) - binary_search(C, i, 1) ans += Ai*Ci return ans # print(m()) print((someone_ans()))
p03557
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SLR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if args else [default for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) def main(): N = I() A, B, C = sorted(LI()), sorted(LI()), sorted(LI()) ans = 0 for bi in B: ans += bisect_left(A, bi) * (N - bisect_right(C, bi)) print(ans) if __name__ == '__main__': main()
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SLR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if args else [default for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) def main(): N = I() A, B, C = sorted(LI()), sorted(LI()), sorted(LI()) ans = 0 for bi in B: left, right = -1, N while right - left > 1: mid = (right + left) // 2 if A[mid] < bi: left = mid else: right = mid tmp = left left, right = -1, N while right - left > 1: mid = (left + right) // 2 if C[mid] > bi: right = mid else: left = mid ans += (tmp + 1) * (N - right) print(ans) if __name__ == '__main__': main()
p03557
def solve(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() A_cand = [0 for i in range(N)] B_cand = [0 for i in range(N)] for i in range(N): cnt = 0 for j in range(N): if B[i] < C[N-j-1]: cnt += 1 else: break B_cand[i] = cnt for i in range(N): cnt = 0 for j in range(N): if A[i] < B[N-j-1]: cnt += B_cand[N-j-1] else: break A_cand[i] = cnt print((sum(A_cand))) solve()
def solve(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() A_cand = [0 for i in range(N)] B_cand = [0 for i in range(N)] skip_loop = 0 for i in range(N): cnt = skip_loop for j in range(N-skip_loop): if B[N-i-1] < C[N-skip_loop-j-1]: cnt += 1 else: break B_cand[N-i-1] = cnt skip_loop = cnt skip_loop = 0 ans = 0 pre_loop_ans = 0 for i in range(N): cnt = skip_loop ans += pre_loop_ans for j in range(N-skip_loop): if A[N-i-1] < B[N-skip_loop-j-1]: ans += B_cand[N-skip_loop-j-1] pre_loop_ans += B_cand[N-skip_loop-j-1] cnt += 1 else: break A_cand[N-i-1] = cnt skip_loop = cnt print(ans) solve()
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) A.sort() B = list(map(int, input().split())) C = list(map(int, input().split())) C.sort() ans = 0 for b in B: top = bisect.bisect_left(A, b) bottom = N - bisect.bisect_right(C, b) ans += top * bottom print(ans)
import bisect N = int(eval(input())) A = list(map(int, input().split())) A.sort() B = list(map(int, input().split())) C = list(map(int, input().split())) C.sort() ans = 0 for i in range(N): top = bisect.bisect_left(A, B[i]) bottom = N - bisect.bisect_right(C, B[i]) ans += top * bottom print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) A.sort() B = list(map(int, input().split())) C = list(map(int, input().split())) C.sort() ans = 0 for i in range(N): top = bisect.bisect_left(A, B[i]) bottom = N - bisect.bisect_right(C, B[i]) ans += top * bottom print(ans)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = list(map(int, input().split())) C = sorted(list(map(int, input().split()))) ans = 0 for i in range(N): top = bisect.bisect_left(A, B[i]) bottom = N - bisect.bisect_right(C, B[i]) ans += top * bottom print(ans)
p03557
N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) sumSunuke = 0 def bs_left(list, target): low, high = 0, len(list) while low < high: mid = (low + high) // 2 if list[mid] < target: low = mid + 1 else: high = mid return low def bs_right(list, target): low, high = 0, len(list) while low < high: mid = (low + high) // 2 if list[mid] > target: high = mid else: low = mid + 1 return low for x in range(N): ab = bs_left(A, B[x]) bc = N - bs_right(C, B[x]) sumSunuke += ab * bc print(sumSunuke)
from bisect import bisect_left, bisect_right N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) sumSunuke = 0 for x in range(N): ab = bisect_left(A, B[x]) bc = N - bisect_right(C, B[x]) sumSunuke += ab * bc print(sumSunuke)
p03557
import bisect n = int(eval(input())) al = list(map(int,input().split())) bl = list(map(int,input().split())) cl = list(map(int,input().split())) al.sort() bl.sort() cl.sort() cnt = 0 for b in bl: a_num = bisect.bisect_left(al,b) c_num = n - bisect.bisect_right(cl,b) cnt += a_num*c_num # cnt += c_num print(cnt)
import bisect n = int(eval(input())) al = list(map(int,input().split())) bl = list(map(int,input().split())) cl = list(map(int,input().split())) al.sort() bl.sort() cl.sort() ans = 0 for b in bl: a_num = bisect.bisect_left(al,b) c_num = n - bisect.bisect_right(cl,b) ans += a_num*c_num print(ans)
p03557
import bisect n = int(eval(input())) al = list(map(int,input().split())) bl = list(map(int,input().split())) cl = list(map(int,input().split())) al.sort() bl.sort() cl.sort() ans = 0 for b in bl: a_num = bisect.bisect_left(al,b) c_num = n - bisect.bisect_right(cl,b) ans += a_num*c_num print(ans)
from bisect import bisect_left, bisect_right n = int(eval(input())) al = list(map(int,input().split())) bl = list(map(int,input().split())) cl = list(map(int,input().split())) al.sort() bl.sort() cl.sort() ans = 0 for b in bl: # b未満の要素の個数 a_cnt = bisect_left(al,b) # bより大きい要素の個数 c_cnt = n - bisect_right(cl,b) ans += a_cnt*c_cnt print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() count = 0 for i in range(N): index_b = bisect.bisect_right(B, A[i]) for j in range(index_b, N): index_c = bisect.bisect_right(C, B[j]) count += N - index_c print(count)
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() count = 0 for b in B: index_b = bisect.bisect_left(A, b) index_c = bisect.bisect_right(C, b) count += (N - index_c) * index_b print(count)
p03557
n = int(eval(input())) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) ans = 0 for i in range(n): for j in range(n - sum(x > a[i] for x in b), n): ans += sum(x > b[j] for x in c) print(ans)
from bisect import bisect_left, bisect_right n = int(eval(input())) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) ans = 0 def bin_search(x, n, flag): if flag == True: return bisect_left(x, n) else: return bisect_right(x, n) for i in range(n): ans += bin_search(a, b[i], True) * (n - bin_search(c, b[i], False)) print(ans)
p03557
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) adic = {} bdic = {} cdic = {} for i in range(len(a)): if a[i] in adic: adic[a[i]] = adic[a[i]] + 1 else: adic.update({a[i]:1}) for i in range(len(b)): if b[i] in bdic: bdic[b[i]] = bdic[b[i]] + 1 else: bdic.update({b[i]:1}) for i in range(len(c)): if c[i] in cdic: cdic[c[i]] = cdic[c[i]] + 1 else: cdic.update({c[i]:1}) summer = 0 for j in list(bdic.keys()): ai = 0 ci = 0 for i in list(adic.keys()): if i < j: ai = ai + adic[i] for k in list(cdic.keys()): if k > j: ci = ci + cdic[k] summer = summer + bdic[j] * ai * ci print(summer)
N = int(eval(input())) a = list(map(int,input().split(" "))) b = list(map(int,input().split(" "))) c = list(map(int,input().split(" "))) #アルゴリズムわからないけどN log N? a.sort() b.sort() c.sort() #O(N)? i,j,k = 0,0,0 ans = 0 while j < N: while i < N and a[i]<b[j] : i += 1 while k < N and c[k]<=b[j]: k += 1 ans += i * (N - k) j += 1 print(ans)
p03557
import bisect N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) ans = 0 for i in B: zyo = bisect.bisect_left(A, i) ge = bisect.bisect_right(C, i) ans += (N-ge)*zyo #print(ans, zyo, ge) print(ans)
import bisect N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) ans = 0 for i in B: ans += (bisect.bisect_left(A, i)) * (N-bisect.bisect_right(C, i)) print(ans)
p03557
import bisect N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) ans = 0 for i in B: ans += (bisect.bisect_left(A, i)) * (N-bisect.bisect_right(C, i)) print(ans)
import bisect N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() B.sort() C.sort() ans = 0 for i in B: num_A = bisect.bisect_left(A, i) num_B = bisect.bisect_right(C, i) ans += num_A * (N - num_B) print(ans)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) asort = sorted(a) bsort = sorted(b) csort = sorted(c) res = 0 for ai in a: bindex = bisect.bisect_right(bsort, ai) if bindex == n: continue for bi in bsort[bindex:]: cindex = bisect.bisect_right(csort, bi) if cindex == n: continue res += n-cindex print(res)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) bsort = sorted(b) csort = sorted(c) res = 0 asum = [0] * n bsum = [0] * n for i in range(n): asum[i] = n - bisect.bisect_right(bsort, a[i]) for i in range(n): bsum[i] = n - bisect.bisect_right(csort, b[i]) bsum.sort() total = 0 for i in range(n): total += bsum[i] bsum[i] = total res = 0 for i in range(n): if asum[i] != 0: res += bsum[asum[i] -1] print(res)
p03557
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) c.reverse() ans=0 max1=n-1 for x in range(n): maxC=c[x] min1=0 while max1-min1>1: zantei=(max1+min1)//2 if b[zantei]>=maxC: max1=zantei else: min1=zantei if b[max1]<maxC: ch=max1 elif b[min1]>=maxC: continue else: ch=min1 for y in range(ch+1): maxB=b[y] max2=n-1 min2=0 while max2-min2>1: zantei1=(max2+min2)//2 if a[zantei1]>=maxB: max2=zantei1 else: min2=zantei1 if a[max2]<maxB: ch1=max2 else: ch1=min2 ans+=ch1+1 print(ans)
def bs_left(list, target): low = 0 high = len(list) while low < high: mid = (low + high) // 2 if target > list[mid]: low = mid + 1 else: high = mid return low def bs_right(list, target): low = 0 high = len(list) while low < high: mid = (low + high) // 2 if target < list[mid]: high = mid else: low = mid + 1 return low n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for b in B: ans += (bs_left(A, b) * (n - bs_right(C, b))) print(ans)
p03557
import bisect n=int(eval(input())) la=sorted(map(int,input().split())) lb=sorted(map(int,input().split())) lc=sorted(map(int,input().split())) countb=[] count1=0 for i in range(n): index=bisect.bisect_left(la,lb[i]) countb.append(index) countb2=[] sum=0 for i in range(n): sum+=countb[i] countb2.append(sum) ans=0 for i in range(n): index=bisect.bisect_left(lb,lc[i]) if index==0: pass else: ans+=countb2[index-1] print(ans)
import bisect n=int(eval(input())) la=sorted(map(int,input().split())) lb=sorted(map(int,input().split())) lc=sorted(map(int,input().split())) ans=0 for i in range(n): index1=bisect.bisect_left(la,lb[i]) index2=bisect.bisect_right(lc,lb[i]) ans+=index1*(n-index2) print(ans)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() cc = {} for i in b: cc[i] = n-bisect.bisect_right(c, i) sum = 0 for i in a: for j in [s for s in b if s > i]: sum += cc[j] print(sum)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() sum = 0 for i in b: sum += bisect.bisect_left(a, i)*(n-bisect.bisect_right(c, i)) print(sum)
p03557
n= int(eval(input())) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) lal = sorted(al,reverse = True) lbl = sorted(bl,reverse = True) lcl = sorted(cl,reverse = True) d =[0]*n for i in range(n): x = lbl[i] for j in range(n): y = lal[j] if x > y: d[i] = (n-j) break res =0 for i in range(n): x = lcl[i] for j in range(n): y = lbl[j] if x >y: res += sum(d[j:]) break print(res)
n= int(eval(input())) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) lal = sorted(al) lbl = sorted(bl) lcl = sorted(cl) from bisect import bisect_left, bisect_right res = 0 for i in range(n): bx = lbl[i] ax = bisect_left(lal,bx) cx = n - bisect_right(lcl,bx) res += ax*cx print(res)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in a: bi = bisect.bisect_right(b,i) for j in b[bi:]: ci = bisect.bisect_right(c,j) ans += (n-ci) print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in b: ai = bisect.bisect_left(a,i) ci = bisect.bisect_right(c,i) ans += ai*(n-ci) print(ans)
p03557
import bisect N = int(eval(input())) # それぞれのパーツの数 A = list(map(int, input().split())) # 小さい B = list(map(int, input().split())) # 中くらい C = list(map(int, input().split())) # 大きい # Cは並び替え不要 A.sort() B.sort() total = 0 for c in C: b_count = bisect.bisect_left(B, c) # bの数量 for b in B[:b_count]: a_count = bisect.bisect_left(A, b) # aの数量 total += a_count print(total)
import bisect import itertools N = int(eval(input())) # それぞれのパーツの数 A = list(map(int, input().split())) # 小さい B = list(map(int, input().split())) # 中くらい C = list(map(int, input().split())) # 大きい # Cは並び替え不要 A.sort() B.sort() # Bの各要素でAを二分探索して返ってきたindexを先に保有しておく b_counts = [0] * N for i in range(N): b_count = bisect.bisect_left(A, B[i]) b_counts[i] = b_count cumsum_b_counts = list(itertools.accumulate(b_counts)) cumsum_b_counts = [0] + cumsum_b_counts # Cの各要素でBを二分探索。上記で保有しておいたb_countsを活用する total = 0 for c in C: count = bisect.bisect_left(B, c) total += cumsum_b_counts[count] print(total)
p03557
#create date: 2020-08-06 09:16 import sys stdin = sys.stdin from bisect import bisect_left def ns(): return stdin.readline().rstrip() def ni(): return int(ns()) def na(): return list(map(int, stdin.readline().split())) def main(): n = ni() a = na() b = na() c = na() a.sort() b.sort() c.sort() cnt = 0 for ci in c: i = bisect_left(b, ci) if i == 0: continue for bi in b[:i]: j = bisect_left(a, bi) cnt += j print(cnt) if __name__ == "__main__": main()
#create date: 2020-08-06 09:16 import sys stdin = sys.stdin from bisect import bisect_left, bisect_right def ns(): return stdin.readline().rstrip() def ni(): return int(ns()) def na(): return list(map(int, stdin.readline().split())) def main(): n = ni() a = na() b = na() c = na() a.sort() b.sort() c.sort() cnt = 0 #print(a, b, c) for bi in b: i = bisect_left(a, bi) j = bisect_right(c, bi) cnt += i * (n-j) #print(bi, i, n-j) print(cnt) if __name__ == "__main__": main()
p03557
def isOK(array, index, key): if array[index] > key: return True else: return False def binary_serch(array, key): ng = -1 ok = len(array) while (abs(ok - ng) > 1): mid = (ok + ng)//2 if isOK(array, mid, key): ok = mid else: ng = mid return ok n = int(eval(input())) array1 = list(map(int,input().split())) array2 = list(map(int,input().split())) array3 = list(map(int,input().split())) # array1 = sorted(array1) array2 = sorted(array2) array3 = sorted(array3) # a = binary_serch(array2, 5) count=0 for array1_index in range(n): start_array2_index = binary_serch(array2, array1[array1_index]) #print(array1[array1_index]) for cor_array2_index in range(start_array2_index, n): #print(array2[cor_array2_index]) start_array3_index = binary_serch(array3, array2[cor_array2_index]) # for k in range(start_array3_index,n): # print(array3) count+=abs(start_array3_index - n) print(count)
def isOK_under(array, index, key): if array[index] >= key: return True else: return False def isOK_over(array, index, key): if array[index] > key: return True else: return False def binary_serch_under(array, key): ng = -1 ok = len(array) while (abs(ok - ng) > 1): mid = (ok + ng)//2 if isOK_under(array, mid, key): ok = mid else: ng = mid return ok def binary_serch_over(array, key): ng = -1 ok = len(array) while (abs(ok - ng) > 1): mid = (ok + ng)//2 if isOK_over(array, mid, key): ok = mid else: ng = mid return ok n = int(eval(input())) array1 = list(map(int,input().split())) array2 = list(map(int,input().split())) array3 = list(map(int,input().split())) array1 = sorted(array1) array2 = sorted(array2) array3 = sorted(array3) # a = binary_serch(array2, 5) count=0 # for array1_index in range(n): # start_array2_index = binary_serch(array2, array1[array1_index]) # # print(array1[array1_index]) # for cor_array2_index in range(start_array2_index, n): # # print(array2[cor_array2_index]) # start_array3_index = binary_serch(array3, array2[cor_array2_index]) # # for k in range(start_array3_index,n): # # print(array3) # count+=abs(start_array3_index - n) for index_array2 in range(n): a = binary_serch_under(array1, array2[index_array2]) c = binary_serch_over(array3, array2[index_array2]) count += a*abs(c-n) print(count)
p03557
n=int(eval(input())) a,b,c=[list(map(int,input().split())) for _ in [0]*3] from itertools import accumulate a.sort() b.sort() c.sort() a+=[10**20] b+=[10**20] p,q=0,0 cnt=0 ans=[0]*n for i in range(n): for j in range(p,n+1): if b[i]>a[j]: pass else: break ans[i]=j p=j ans=[0]+list(accumulate(ans)) for i in range(n): for j in range(q,n+1): if c[i]>b[j]: pass else: break cnt+=ans[j] print(cnt)
n=int(eval(input())) a,b,c=[list(map(int,input().split())) for _ in [0]*3] from itertools import accumulate a.sort() b.sort() c.sort() a+=[10**20] b+=[10**20] p,q=0,0 cnt=0 ans=[0]*n for i in range(n): for j in range(p,n+1): if b[i]>a[j]: pass else: break ans[i]=j p=j ans=[0]+list(accumulate(ans)) for i in range(n): for j in range(q,n+1): if c[i]>b[j]: pass else: break q=j cnt+=ans[j] print(cnt)
p03557
from bisect import bisect_left n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() # print(A) # print(B) # print(C) A_B = [] for i in range(n): A_B.append(bisect_left(A, B[i])) ruisekiwa = [A_B[0]] for i in range(1, n): ruisekiwa.append(ruisekiwa[-1] + A_B[i]) # print(A_B) # print(ruisekiwa) ans = 0 for i in range(n): idx = bisect_left(B, C[i]) if idx: ans += ruisekiwa[idx-1] print(ans)
from bisect import bisect_left, bisect_right n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for i in range(n): ans += bisect_left(A, B[i]) * (n - bisect_right(C, B[i])) print(ans)
p03557
N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() BClist = [] for i in range(N): for j in range(N): if(B[i] < C[j]): BClist.append(N-j) break ans = 0 for k in range(N): for i in range(N): if(A[k] < B[i]): ans += sum(BClist[i:]) break print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) ans = 0 a.sort() b.sort() c.sort() for j in range(n): ans += bisect.bisect_left(a,b[j])*(n-bisect.bisect_right(c,b[j])) print(ans)
p03557
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) cnt = 0 for j in range(N): target = B[j] insert_indexA = bisect.bisect_left(A, target) insert_indexC = bisect.bisect_right(C, target) cnt = cnt + len(A[:insert_indexA]) * len(C[insert_indexC:]) print(cnt)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) cnt = 0 for j in range(N): target = B[j] insert_indexA = bisect.bisect_left(A, target) insert_indexC = bisect.bisect_right(C, target) cnt = cnt + insert_indexA * (len(C)-insert_indexC) print(cnt)
p03557
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() ans=0 for i in range(n): j=bisect.bisect_left(b,a[i]+1) if j>=n: break for k in range(j,n): l=bisect.bisect_left(c,b[k]+1) if l>=n: break ans+=n-l print(ans)
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() ans=0 for i in range(n): j=bisect.bisect_left(a,b[i]) k=n-bisect.bisect_right(c,b[i]) ans+=j*k print(ans)
p03557
import sys input = sys.stdin.readline n=int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans=0 bfla=0 cfla=0 for i in range(n): x=a[i] bfla=0 cfla=0 for j in range(bfla,n): if b[j] > x : y=b[j] bfla=j else: continue for k in range(cfla,n): if c[k]>y: z=c[k] ans+=n-k cfla=k break print(ans)
import sys import bisect input = sys.stdin.readline n=int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans=0 for j in range(n): al=bisect.bisect_left(a,b[j]) cl=n-bisect.bisect_right(c,b[j]) ans+=al*cl print(ans)
p03557
N = int(eval(input())) A = [int(a) for a in input().split()] B = [int(b) for b in input().split()] C = [int(c) for c in input().split()] A_sorted = sorted(A) B_sorted = sorted(B) C_sorted = sorted(C) ans = 0 for b in B_sorted: #Aのうちbより小さいの数 left = -1 right = N while right - left > 1: mid = left + (right - left) // 2 if A_sorted[mid] < b: left = mid else: right = mid a_count = right #Cのうちbより大きいの数 left = -1 right = N while right - left > 1: mid = left + (right - left) // 2 if C_sorted[mid] > b: right = mid else: left = mid c_count = N - right ans += a_count * c_count print(ans)
import bisect N = int(eval(input())) A = [int(a) for a in input().split()] B = [int(b) for b in input().split()] C = [int(c) for c in input().split()] A_sorted = sorted(A) B_sorted = sorted(B) C_sorted = sorted(C) ans = 0 for b in B_sorted: #Aのうちbより小さいの数 a_count = bisect.bisect_left(A_sorted, b) #Cのうちbより大きいの数 c_count = N - bisect.bisect_right(C_sorted, b) ans += a_count * c_count print(ans)
p03557
from collections import Counter def altar(a,b): cnt = 0 for k in range(len(b)): while a and a[0][0]<b[k][0]: cnt += a.pop(0)[1] b[k] = (b[k][0],b[k][1]*cnt) eval(input()) a,b,c = [sorted(list(dict(Counter(list(map(int,input().split())))).items()),key=lambda x:x[0])for _ in "abc"] altar(a,b) altar(b,c) print((sum([x[1] for x in c])))
import bisect n=int(eval(input())) a,b,c = [sorted(map(int,input().split())) for _ in "abc"] print((sum([bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x)) for x in b])))
p03557
import bisect n = int(eval(input())) aa = list(sorted(map(int, input().split()))) bb = list(sorted(map(int, input().split()))) cc = list(sorted(map(int, input().split()))) ans = 0 for a in aa: bi = bisect.bisect(bb, a) bx = len(bb) - bi for b in range(bi, len(bb)): ci = bisect.bisect(cc, bb[b]) cx = len(cc) - ci ans += cx print(ans)
import bisect n = int(eval(input())) aa = list(sorted(map(int, input().split()))) bb = list(sorted(map(int, input().split()))) cc = list(sorted(map(int, input().split()))) ans = 0 for b in bb: ax = bisect.bisect_left(aa, b) ci = bisect.bisect(cc, b) cx = len(cc) - ci ans += ax * cx print(ans)
p03557
import copy n =int(eval(input())) a=[] b=[] c=[] a =list(map(int,input().split())) a.sort() b =list(map(int,input().split())) b.sort() c =list(map(int,input().split())) c.sort() c2 = copy.copy(c) b_limit = 0 c_limit =0 count =0 c_count =0 b_score =[0]*n for i in a: c_count =0 c = copy.copy(c2) if b_limit == 1: break for j in reversed(list(range(len(b)))): if b[j] <= i: if b[j] == max(b): b_limit +=1 break else: if not b_score[j] == 0: count += b_score[j] continue if len(c) ==0: count +=c_count if b_score[j] ==0: b_score[j] = c_count continue for k in reversed(list(range(len(c)))): if c[k] <= b[j]: count += c_count if b_score[j] ==0: b_score[j] = c_count break c.pop(k) c_count +=1 if k == 0: count +=c_count if b_score[j] ==0: b_score[j] = c_count print(count)
import bisect ans =0 n =int(eval(input())) a =list(map(int,input().split())) a.sort() b =list(map(int,input().split())) b.sort() c =list(map(int,input().split())) c.sort() for i in b: s = bisect.bisect_right(c,i) s_num = n-s t = bisect.bisect_left(a,i) t_num = t ans += s_num * t_num print(ans)
p03557
N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort();C.sort() M = 0 for i in range(N): low = 0 high = N - 1 t = (low + high) // 2 if A[N-1] < B[i]: t = N-1 elif A[0] >= B[i]: t = -1 else: while (low <= high): if A[t] < B[i] <= A[t+1]: break elif B[i] <= A[t]: high = t elif A[t+1] < B[i]: low = t+1 t = (low + high) // 2 low = 0 high = N - 1 s = (low + high) // 2 if C[N-1] <= B[i]: s = N-1 elif B[i] < C[0]: s = -1 else: while (low <= high): if C[s] <= B[i] < C[s+1]: break elif B[i] < C[s]: high = s elif C[s+1] <= B[i]: low = s + 1 s = (low + high) // 2 M += (t+1)*(N-s-1) print(M)
from bisect import bisect_left,bisect_right N=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] C=[int(i) for i in input().split()] A.sort() C.sort() ans=0 for i in range(N): ans+=bisect_left(A,B[i])*(N-bisect_right(C,B[i])) print(ans)
p03557
from bisect import bisect_left,bisect_right;N=int(eval(input()));A=sorted([int(i) for i in input().split()]);B=[int(i) for i in input().split()];C=sorted([int(i) for i in input().split()]);ans=0 for i in range(N):ans+=bisect_left(A,B[i])*(N-bisect_right(C,B[i])) print(ans)
from bisect import bisect_left,bisect_right;N=int(eval(input()));A=sorted([int(i) for i in input().split()]);B=[int(i) for i in input().split()];C=sorted([int(i) for i in input().split()]);print((sum([bisect_left(A,B[i])*(N-bisect_right(C,B[i])) for i in range(N)])))
p03557
from bisect import bisect_left,bisect_right;N=int(eval(input()));A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print((sum([bisect_left(A,B[i])*(N-bisect_right(C,B[i])) for i in range(N)])))
from bisect import bisect_left,bisect_right;N=int(eval(input()));A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print((sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B])))
p03557