Problem:


Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Accepted

Solution code:
# 真ん中[中部]を固定化して考える
import bisect

n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]

# まずは昇順ソート
a.sort()
b.sort()
c.sort()

# 答え格納する変数
ans = 0

# 全てのb[i]に対して a < b[i] < c となるaとcを探す
for i in range(n):
    center_size = b[i]
    left_idx = bisect.bisect_right(a, center_size-1)
    right_idx = bisect.bisect_left(c, center_size+1)
    ans += left_idx * (n-right_idx)
print(ans)

Submission status: Accepted

Solution code:
import bisect

n=int(input())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ans=0

for i in range(n):
    x=bisect.bisect_right(a,b[i]-1)
    y=n-bisect.bisect_left(c,b[i]+1)

    ans+=x*y

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
 
N = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

A.sort()
B.sort()
C.sort()

A_cnt = np.searchsorted(A, B, side='left')
C_cnt = np.searchsorted(C, B, side='right')

ans = (A_cnt * (N-C_cnt)).sum()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
 
N = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

A.sort()
C.sort()

A_cnt = np.searchsorted(A, B, side='left')
C_cnt = np.searchsorted(C, B, side='right')

ans = (A_cnt * (N-C_cnt)).sum()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
 
N = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

A.sort()
C.sort()

ans = 0
for i in range(N):
	b = B[i]
	A_cnt = np.searchsorted(A, b, side='left')
	C_cnt = np.searchsorted(C, b, side='right')
	ans += A_cnt * (N-C_cnt)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys

N = int(input())
#I = np.array(sys.stdin.read().split(), np.int64)
#A = I[:N]
#B = I[N:2*N]
#C = I[2*N:]

A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
C = np.array(list(map(int,input().split())))

A.sort()
C.sort()

ans = 0
for i in range(N):
	b = B[i]
	A_cnt = np.searchsorted(A, b, side='left')
	C_cnt = np.searchsorted(C, b, side='right')
	ans += A_cnt * (N-C_cnt)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys

N = int(input())
I = np.array(sys.stdin.read().split(), np.int64)
A = I[:N]
B = I[N:2*N]
C = I[2*N:]

A.sort()
C.sort()

ans = 0
for i in range(N):
	b = B[i]
	A_cnt = np.searchsorted(A, b, side='left')
	C_cnt = np.searchsorted(C, b, side='right')
	ans += A_cnt * (N-C_cnt)

print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(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):
  index_a = bisect.bisect_left(a, b[i])
  index_c = bisect.bisect_right(c, b[i])
  
  ans += index_a * (n - index_c)
  
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
def to_list():
  return list(map(int, input().split()))

a = to_list()
b = to_list()
c = to_list()

a.sort()
c.sort()

ans = 0
for n in b:
  ans += bisect.bisect_left(a, n) * (len(c) - bisect.bisect_right(c, n))

print(ans)

Submission status: Accepted

Solution code:
import bisect as bi
n=int(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:
    A=bi.bisect_left(a,i)
    C=n-bi.bisect_right(c,i)
    ans+=A*C
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline
N = int(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 :
    al = bisect.bisect_left(A,b)
    cg = N - bisect.bisect_right(C,b)
    ans += al * cg

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(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()
cnt = 0

for b in B:
    a_index = bisect.bisect_left(A,b)
    c_index = bisect.bisect_right(C,b)
    cnt += a_index*(len(C)-c_index)

print(cnt)

Submission status: Accepted

Solution code:
N = int(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()
an, bn, cn = -1, -1, 0
nf = 0
ans = [0]*N
for cn in range(N):
    flag = 0
    if cn > 0:
        ans[cn] = ans[cn-1]
    while flag == 0:
        flag = 1
        while bn < N - 1 and B[bn + 1] < C[cn]:
            bn += 1
            flag = 0
            while an < N - 1 and A[an + 1] < B[bn]:
                an += 1
            ans[cn] += an + 1
print(sum(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
B_list = list(map(int, input().rstrip().split()))
C_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()
B_list.sort()
C_list.sort()

cnt=0
for i in B_list:
    ind_A = bisect.bisect_left(A_list, i)
    ind_C = bisect.bisect_right(C_list, i)
    cnt +=  ind_A * (N - ind_C)

print(cnt)

Submission status: Accepted

Solution code:
def count_a(A, x):
    low = -1
    high = N
    while high - low > 1:
        mid = (high + low) // 2
        if A[mid] < x:
            low = mid
        else:
            high = mid
    return low + 1

def count_c(C, y):
    low = -1
    high = N
    while high - low > 1:
        mid = (high + low) // 2
        if C[mid] > y:
            high = mid
        else:
            low = mid
    return N - high

N = int(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
A_min = A[0]
C_max = C[-1]

for b in B:
    if b <= A_min or b >= C_max:
        continue

    ans += count_a(A, b) * count_c(C, b)

print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    c.sort()
    ans = 0
    for i in range(n):
        bi = b[i]
        j = bisect.bisect_left(a,bi)
        k = bisect.bisect_right(c,bi)
        ans += j*(n-k)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
c.sort()
from bisect import bisect_left
from bisect import bisect_right
ans=0
for b in b:
    aa=bisect_left(a,b)
    cc=bisect_right(c,b)
    ans+=aa*(n-cc)
print(ans)

Submission status: Accepted

Solution code:
def binary_search1(A, i):
    l = 0
    r = len(A)
    if i <= A[1]:
        return 0
    while True:
        m = (r + l) // 2
        if A[m] < i <= A[m + 1]:
            return m
        if A[m] < i:
            l = m + 1
        elif A[m] >= i:
            r = m

def binary_search2(A, i):
    l = 0
    r = len(A)
    if i >= A[len(A) - 2]:
        return 0
    while True:
        m = (r + l) // 2
        if A[m] <= i < A[m + 1]:
            return len(A) - m - 2
        if A[m] <= i:
            l = m + 1
        elif A[m] > i:
            r = m

n = int(input())
a = [0] + sorted(list(map(int, input().split()))) + [10 ** 10]
b = list(map(int, input().split()))
c = [0] + sorted(list(map(int, input().split()))) + [10 ** 10]
ans = 0
for i in b:
    ans += binary_search1(a, i) * binary_search2(c, i)
print(ans)

Submission status: Accepted

Solution code:
import bisect
import numpy as np
n = int(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):
     s = bisect.bisect_left(a,b[i])
     t = n - bisect.bisect_right(c,b[i])
     ans += s*t

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
check = [0] * N
ans = 0
for i in range(N):
    check[i] = N - bisect.bisect_right(C,B[i])
for i in range(1,N):
    check[N-1-i] += check[N-i]
for i in range(N):
    b = bisect.bisect_right(B,A[i])
    if b == N:
        continue
    ans += check[b]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a, b[i])
    y = bisect.bisect_right(c, b[i])
    ans += x * (n - y)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect_right
n=int(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):
  indea=bisect_left(a,b[i])
  indec=bisect_right(c,b[i])
  ans+=indea*(n-indec)
print(ans)

Submission status: Accepted

Solution code:
import math 
import bisect
import heapq
from collections import deque

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
c.sort()
ans = 0
for i in range(n):

    idx1 = bisect.bisect_left(a, b[i])
    idx2 = n - bisect.bisect_right(c, b[i])
    ans += (idx1 * idx2)

print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline

n = int(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
ans = 0
memo = [0] * n

for i in range(n):
    insert_index_c = bisect.bisect_right(c, b[i])
    cnt += n - insert_index_c
    memo[i] += cnt

for i in range(n):
    if a[i] > b[n - 1]:
        break
    insert_index_b = bisect.bisect_right(b, a[i])  # 昇順
    if insert_index_b >= 1:
        ans += memo[n - 1] - memo[insert_index_b - 1]
    else:
        ans += memo[n - insert_index_b - 1]

print(ans)

Submission status: Accepted

Solution code:
import bisect


n = int(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()

b_list = []
c_list = []

for i in b:
    b_list.append(bisect.bisect_left(a, i))

for i in c:
    c_list.append(bisect.bisect_left(b, i))

b_sum = []
bbb = 0
for i in b_list:
    bbb += i
    b_sum.append(bbb)
sum = 0
for i in c_list:
    if i == 0:
        sum += 0
    else:
        sum += b_sum[i-1]

print(sum)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = list(map(int, input().split(" ")))
bottoms = sorted(list(map(int, input().split(" "))))
# print(tops)
# print(mids)
# print(bottoms)


# def left_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] >= num:
#         return left_binary_search(check_list, num, left, mid - 1)
#     else:
#         return left_binary_search(check_list, num, mid + 1, right)


# def right_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] > num:
#         return right_binary_search(check_list, num, left, mid - 1)
#     else:
#         return right_binary_search(check_list, num, mid + 1, right)


total_count = 0
for mid in mids:
    # bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1)
    bottom_start_index = bisect.bisect_right(bottoms, mid)
    # top_end_index = left_binary_search(tops, mid, 0, N - 1)
    top_end_index = bisect.bisect_left(tops, mid)
    total_count += ((N - bottom_start_index) * top_end_index)
print(total_count)

Submission status: Accepted

Solution code:
N = int(input())
AAA = sorted([int(i) for i in input().split()])
BBB = sorted([int(i) for i in input().split()])
CCC = sorted([int(i) for i in input().split()])

def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid

def lower_bound(T,SSS):#スライスの値を返す。同じ値があったら左寄りに出す
    left = 0 #SSS[left]はTと同じかそれより小さい
    right = len(SSS)-1 #SSS[right]はTより真に大きい

    if T<=SSS[left]:
        return 0
    if T>SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<T:
            left = mid
        else:
            right = mid

ans=0
lenCCC = len(CCC)
for B in BBB:
    nA = lower_bound(B,AAA)
    nC = lenCCC-upper_bound(B,CCC)
    ans+=nA*nC
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
#A = [LIST() for i in range(3)]
A = LIST()
B = LIST()
C = LIST()
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    right = N - c
    ans += a * right
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = sorted(LIST())
B = sorted(LIST())
C = sorted(LIST())

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    f = False

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            f = True
            break
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    if f:
        return high
    return low

b = [0]*N
for i in range(N):
	b[i] = bisect_left(A, B[i])

c = [0]*N
for i in range(N):
	c[i] = bisect_left(B, C[i])

bb = [0] + list(accumulate(b))

s = 0
for i in range(len(c)):
	s += bb[c[i]]
print(s)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def f(a, x):
    return a[x]


def binary_search(s, t, d, target):
    ok = s - 1
    ng = t

    while ng - ok > 1:
        mid = (ng + ok) // 2
        if f(d, mid) <= target:
            ok = mid
        else:
            ng = mid

    return ok


# 二分探索 ok ng
def main():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    A = sorted(A)
    C = sorted(C)
    ans = 0
    # print(A)
    # print(C)

    for i in range(N):
        a_idx = bisect.bisect_left(A, B[i])
        c_idx = bisect.bisect_right(C, B[i])
        ans += a_idx * (N - c_idx)
        # print(B[i], a_idx * (N - c_idx))
        # print(B[i], a_idx, c_idx)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0
for b in B:
    a = bisect_left(A, b)
    c = N - bisect_right(C, b)
    ans += a * c

print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
b_memo = [0]
for b in B:
    a = bisect.bisect_left(A, b)
    b_memo.append(b_memo[-1]+a)
for c in C:
    b = bisect.bisect_left(B, c)
    if (b == 0):
        continue
    ans += b_memo[b]
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A_list = sorted(list(map(int,input().split())))
B_list = sorted(list(map(int,input().split())))
C_list = sorted(list(map(int,input().split())))
ans = 0
for B in B_list:
    a_cnt = bisect.bisect_left(A_list,B)
    c_cnt = len(C_list) - bisect.bisect_right(C_list,B)
    ans += a_cnt * c_cnt
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import bisect
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
B.sort()
C.sort()

ans = 0

for b in B:
    a = bisect.bisect_left(A,b)
    c = N - bisect.bisect_right(C,b)
    ans += (a*c)
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(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()

ans = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = N-bisect.bisect_right(C,b)
    ans += a_cnt*c_cnt

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
from bisect import bisect_left, bisect_right
n = int(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()

ans = 0
for j in b:
    A = bisect_left(a, j)
    C = bisect_right(c, j)
    ans += A * (n - C)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(),dtype = np.int64)
B = np.array(input().split(),dtype = np.int64)
C = np.array(input().split(),dtype = np.int64)
A.sort()
B.sort()
C.sort()

cnt_a = np.searchsorted(A,B,side='left')
unavailabel_cnt_c = np.searchsorted(C,B,side='right')
cnt_c = N-unavailabel_cnt_c
ans = (cnt_a*cnt_c).sum()
print(ans)

Submission status: Accepted

Solution code:
N = int(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()])

import bisect

ans = 0
for i in range(N):
    lefta = bisect.bisect_left(a, b[i])
    leftc = N - bisect.bisect_right(c, b[i])

    ans += lefta * leftc

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for b in B:
    n_a = bisect.bisect_left(A, b)
    n_c = l_c - bisect.bisect_right(C, b)
    ans += n_a*n_c
print(ans)

Submission status: Accepted

Solution code:
f=lambda:sorted(map(int,input().split()))
n=int(input())
a,b,c=f(),f(),f()
from bisect import *
print(sum(bisect_left(a,i)*(n-bisect_right(c,i)) for i in b))

Submission status: Accepted

Solution code:
n=int(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()]
import bisect
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)

Submission status: Accepted

Solution code:
import bisect
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    C.sort()

    ans = 0
    for target in B:
        A_lower = bisect.bisect_left(A, target)
        C_upper = bisect.bisect_right(C, target)
        ans += A_lower * (N - C_upper)
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from bisect import (
    bisect_left,
    bisect_right
)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    c.sort()

    ans = 0
    for target in b:
        ans += bisect_left(a, target) * (len(c) - bisect_right(c, target))
    print(ans)

main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    c.sort()

    def bs(seq, target, key_):
        first = 0
        last = len(seq) - 1
        if key_ == '<=':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] <= target:
                    first = middle
                else:
                    last = middle
            if seq[first] <= target < seq[last]:
                return first
            elif target < seq[first]:
                return
            else:
                return len(seq) - 1
        if key_ == '<':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] < target:
                    first = middle
                else:
                    last = middle
            if seq[first] < target <= seq[last]:
                return first
            elif target <= seq[first]:
                return
            else:
                return len(seq) - 1
        if key_ == '>=':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] < target:
                    first = middle
                else:
                    last = middle
            if seq[first] < target <= seq[last]:
                return last
            elif target <= seq[first]:
                return 0
            else:
                return
        if key_ == '>':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] <= target:
                    first = middle
                else:
                    last = middle
            if seq[first] <= target < seq[last]:
                return last
            elif target < seq[first]:
                return 0
            else:
                return
    
    ans = 0
    for target in b:
        aindex = bs(a, target, '<')
        if aindex is None:
            continue
        cindex = bs(c, target, '>')
        if cindex is None:
            continue
        ans += (aindex + 1) * (len(c) - cindex)
    print(ans)

main()

Submission status: Accepted

Solution code:
#abc077 c
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
c.sort()
ans=0
for i in b:
    na=bisect.bisect_left(a,i)
    nc=len(b)-bisect.bisect_right(c,i)
    ans+=(na*nc)
print(ans)

Submission status: Accepted

Solution code:
n = int(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()

BtoC = [0]*(n+1)
for i in range(n):
  bin_l, bin_r = 0, n
  while bin_r - bin_l > 1:
    key = (bin_r + bin_l)//2
    if b[i] >= c[key]:
      bin_l = key
    else:
      bin_r = key
  if bin_l == n-1 and b[i] < c[-1]:
    BtoC[i] = 1
  elif bin_r == 1 and b[i] < c[0]:
    BtoC[i] = n
  else:
    BtoC[i] = n-bin_r

for i in range(n-1, -1, -1):
  BtoC[i] += BtoC[i+1]

ans = 0
for i in range(n):
  bin_l, bin_r = 0, n
  while bin_r - bin_l > 1:
    key = (bin_r + bin_l)//2
    if a[i] >= b[key]:
      bin_l = key
    else:
      bin_r = key
  if bin_l == n-1 and a[i] < b[-1]:
    ans += BtoC[n-1]
  elif bin_r == 1 and a[i] < b[0]:
    ans += BtoC[0]
  else:
    ans += BtoC[bin_r]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(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)

Submission status: Accepted

Solution code:
import bisect

N=int(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 i in range(N):
    cnt += bisect.bisect_left(A,B[i]) * (N - bisect.bisect_right(C, B[i]))

print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect_right
n = int(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 x in b:
    ans += bisect_left(a,x)*(n-bisect_right(c,x))
print(ans)

Submission status: Accepted

Solution code:
N = int(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)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
n = int(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 b:
    x = bisect_left(a, i)
    y = n - bisect_right(c, i)
    ans += x * y
print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

A.sort()
C.sort()


for b in B:
  a = bisect.bisect_left(A, b)
  c = N - bisect.bisect_right(C, b)
  ans += a * c
  
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

N = int(raw_input())

A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0
A_on_B = 0
C_under_B = 0
for y in B:
    A_on_B = bisect_left(A, y) 
    C_under_B = N - bisect_right(C, y) 
    ans = ans + A_on_B*C_under_B
print ans