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:
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()

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

ans = 0

BtoC = [None] * N
for i in range(0, N):
    BtoC[i] = N - binsearch(B[i], C)
#print(BtoC)

cumulative=[0]
for i in range(N):
    cumulative.append(cumulative[i] + BtoC[N-i-1])
#print(cumulative)
cumulative.reverse()
#print(cumulative)

for j in range(0, N):
    temp = binsearch(A[j], B)
    ans += cumulative[temp]

print(ans)

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()

import bisect
ans = 0
for b in B:
    idx_a = bisect.bisect_left(A,b)
    idx_c = bisect.bisect_right(C,b)
    
    ans += idx_a*(N-idx_c)
    
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 B:
    tmpa = bisect.bisect_left(A, i)
    tmpc = N - bisect.bisect_right(C, i)
    ans += tmpa*tmpc
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()
c.sort()

ans = 0
for i in range(len(b)):
    a_idx = bisect.bisect_left(a, b[i])
    c_idx = bisect.bisect_right(c, b[i])
    ans += a_idx * (n - c_idx)
print(ans)

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

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

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
A, B, C = [sorted([int(x) for x in input().split()]) for i in range(3)]
lst = []
res = 0
for b in B:
  res += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(res)

Submission status: Accepted

Solution code:
from itertools import permutations
import sys
import heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from collections import deque
from fractions import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#ここから書き始める
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:
    total1 = bisect_left(a, i)
    total2 = n - bisect_right(c, i)
    ans += total1 * total2
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())))
count = 0
for i in b:
  t = bisect.bisect_left(a,i)
  q = n-bisect.bisect_right(c,i)
  count += t*q
print(count)

Submission status: Accepted

Solution code:
def isok(x,b):
    if x>b:
        return True
    else:
        return False
def bisect(ls,val): ##bの関数isok(val)がTrueとなる一番右のindexを返す
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2

    return ok


n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt = [0]*(n+1) ##cnt[i] ==　B[i]以上の(b,c)の組の数
for i in range(n):
    b = B[i]
    cnt[i] = bisect(C,b)+1  ##okの数
    if i!=0:
        cnt[i]+=cnt[i-1]
ans = 0
for a in A:
    idx = bisect(B,a) #使える最小のbのインデックス
    ans += cnt[idx]
print(ans)

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()

ans = 0


numB = [0] * N

j = 0

for i, b in enumerate(B):
    while j < N and b >= C[j]:
        j += 1
    numB[i] = N-j

for i in range(N-2, -1, -1):
    numB[i] += numB[i+1]

j = 0

for i, a in enumerate(A):
    while j < N and a >= B[j]:
        j += 1
    if j < N:
        ans += numB[j]


print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

bc=[0]*N
bcsum=[0]*N

for i in range(N):
    b=B[i]
    bc[i]=N-bisect_right(C,b)

bcsum[0]=sum(bc)

for i in range(1,N):
    bcsum[i]=bcsum[i-1]-bc[i-1]
ans=0
for a in A:
    p=bisect_right(B,a)
    if p<N:
        ans+=bcsum[p]

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
# import numpy as np

import bisect

def main():
	N=II()
	A=LI()
	B=LI()
	C=LI()
	A.sort()
	B.sort()
	C.sort()
	BB=[0]*N
	ans=0
	for i,b in enumerate(B):
		BB[i]=N-bisect.bisect_right(C,b)
	BB.append(0)
	for i in range(N-2,-1,-1):
		BB[i]+=BB[i+1]
	for a in A:
		ans+=BB[bisect.bisect_right(B,a)]
	print(ans)



if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import bisect

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:
    left = bisect.bisect_left(A, i)
    right = N - bisect.bisect_right(C, i)
    ans += left * right

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())))
print(sum(bisect.bisect_left(A, i)*(N-bisect.bisect_right(C, i)) for i in B))

Submission status: Accepted

Solution code:
INF = int(1e9) + 7

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()
b.reverse()
c.reverse()
j = 0
c.insert(0,INF)
c.append(0)
for i in range(n):
    while b[i] < c[j] and j <= n:
        j += 1
    b[i] = [b[i], j-1]
#print(b)
#print(c)
#print(b)
a.reverse()
cnt = 0
ans = 0
b.insert(0,[INF, 0])
b.append([0,0])
j = 0
for i in range(n):
    while a[i] < b[j][0] and j <= n:
        cnt += b[j][1]
        j += 1



    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [(int(i), 0) for i in input().split()]
b = [(int(i), 1) for i in input().split()]
c = [(int(i), 2) for i in input().split()]

d = {}
for i, j in sorted(a + b + c):
    if i in d:
        d[i].append(j)
    else:
        d[i] = [j]


x = 0
y = 0
z = 0

for i in sorted(list(d)):
    xx = x
    yy = y

    for j in d[i]:
        if j == 0:
            x = x + 1
        elif j == 1:
            y += xx
        else:
            z += yy

print(z)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
import bisect

def resolve():
    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_r = bisect.bisect_left(A, b)
        c_l = bisect.bisect_right(C, b)
        ans += a_r * (N - c_l)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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()

    def binsearch_left(a, x):
        l = -1
        r = len(a)
        while r-l>1:
            m = (l+r)//2
            if x<a[m]:
                r = m
            else:
                l = m
        return r

    def binsearch_right(a, x):
        l = -1
        r = len(a)
        while r-l>1:
            m = (l+r)//2
            if x<=a[m]:
                r = m
            else:
                l = m
        return r

    ans = 0
    for b in B:
        a_r = binsearch_right(A, b)
        c_l = binsearch_left(C, b)
        ans += a_r * (N - c_l)

    print(ans)

if __name__ == '__main__':
    resolve()

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()
C.sort()

ans = 0

for b in B:
    indexA = bisect.bisect_left(A, b)
    indexC = bisect.bisect_right(C, b)

    ans += indexA * (N-indexC)

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 middle in b:
    tmp1 = bisect.bisect_left(a, middle)
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = list(map(int, input().split()))
    C = sorted(list(map(int, input().split())))

    count = 0
    for b in B:
        i = bisect_left(A, b)
        k = bisect_right(C, b)
        count += i * (len(C) - k)
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_right
from itertools import accumulate

def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    B_counts = []
    for b in B:
        i = bisect_right(C, b)
        B_counts.append(len(C) - i)
    B_counts_cumsum = list(accumulate(B_counts))
    B_counts_cumsum.insert(0, 0)

    count = 0
    for a in A:
        i = bisect_right(B, a)
        if i == len(B):
            continue
        count += B_counts_cumsum[-1] - B_counts_cumsum[i]

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect



def resolve():
    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()
    B.sort()
    C.sort()

    B2=[bisect.bisect_left(A,i)  for i in B]

    for i in range(1,N):
        B2[i]+=B2[i-1]
    C2=[bisect.bisect_right(B,i-1) for i in C]

    print(sum([B2[i-1]  for i in C2 if i != 0 ]))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def binary_search_a(c1, c2):
    global i
    m = (c1 + c2) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if a[m - 1] < i:
            c1 = m
        else:
            c2 = m
        return binary_search_a(c1, c2)

def binary_search_c(c1, c2):
    global i
    m = (c1 + c2) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if c[m - 1] > i:
            c1 = m
        else:
            c2 = m
        return binary_search_c(c1, c2)

n = int(input())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = (sorted(list(map(int, input().split()))))
c.reverse()
ans = 0
for i in b:
    ans += binary_search_a(0, n + 1) * binary_search_c(0, n + 1)
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()
C.sort()

ans = 0
for b in B:
    acnt = bisect_left(A, b)
    ccnt = N - bisect_right(C, b)
    ans += acnt * ccnt
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()
c.sort()

ans = 0
for m in b:
    idx_a = bisect_left(a, m)
    idx_c = bisect_right(c, m)
    ans += idx_a * (n - idx_c)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
def main():
    N=int(input())
    A=sorted([int(_) for _ in input().split()])
    B=sorted([int(_) for _ in input().split()])
    C=sorted([int(_) for _ in input().split()])
    ans=0
    for b in B:
        ans += bisect_left(A,b) * (N-bisect_right(C,b))
    print(ans)
main()

Submission status: Accepted

Solution code:
#binary_search
from bisect import bisect_left
from bisect import bisect_right
#input
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):
    ab = bisect_left(A,B[i])
    bc = N-bisect_right(C,B[i])
    #print(ab, end='  ')
    #print(bc)
    ans += ab*bc
print(ans)

'''
A ●  ○  ○  ○  ○  ○ << ab
    ^ bisec_left(A,B[i])

B ○  ○  #  ○  ○  ○  << # = B[i]

C ○  ○  ○  ●  ●  ●  << bc
          ^ bisec_right(C,B[i])

ab * bc が i のときの組み合わせの数になる
'''

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
ans = 0
for i in range(N):
    ab = bisect_left(A,B[i])
    bc = N-bisect_right(C,B[i])
    #print(ab, end='  ')
    #print(bc)
    ans += ab*bc
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()))

def bisect_l(b):
    l=-1
    r=n
    while l+1<r:
        m=(l+r)//2
        if A[m]<b:
            l=m
        else:
            r=m
    return l

def bisect_r(b):
    l=-1
    r=n
    while l+1<r:
        m=(l+r)//2
        if C[m]>b:
            r=m
        else:
            l=m
    return r
r=0
for b in B:
    a=bisect_l(b)+1
    c=n-bisect_r(b)
    r+=a*c
print(r)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc077/tasks/arc084_a
# 16:40-17:19 done


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

    A = sorted(A, reverse=True)
    B = sorted(B, reverse=True)
    C = sorted(C, reverse=True)

    n_C_for_B = [0] * N
    c = 0
    for b in range(N):
        if C[-1] > B[b]:
            # c = N
            n_C_for_B[b] = N
        else:
            # c = 0
            while C[c] > B[b]:
                c += 1
            n_C_for_B[b] = c

    n_B_for_A = [0] * N
    b = 0
    for a in range(N):
        if B[-1] > A[a]:
            n_B_for_A[a] = N
        else:
            while B[b] > A[a]:
                b += 1
            n_B_for_A[a] = b
    
    n_B = [0] * N
    i = 0
    for a in range(N):
        if n_B_for_A[a] == 0:
            continue

        while i <= n_B_for_A[a]-1:
            n_B[i] = N-a
            i += 1
    
    ans = 0
    for i in range(N):
        ans += n_B[i] * (n_C_for_B[i])
    
    return ans


print(main())

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect_right
def main():
    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 b in B:
        a = bisect_left(A,b)
        c = bisect_right(C,b)
        ans += a*(N-c)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
import bisect

# N = 2
# ARR = [1, 5]
# BRR = [2, 4]
# CRR = [3, 6]

# N = 3
# ARR = [1, 1, 1]
# BRR = [2, 2, 2]
# CRR = [3, 3, 3]

# N = 6
# ARR = [3, 14, 159, 2, 6, 53]
# BRR = [58, 9, 79, 323, 84, 6]
# CRR = [2643, 383, 2, 79, 50, 288]

N = int(input())
ARR = [int(s) for s in input().split(" ")]
BRR = [int(s) for s in input().split(" ")]
CRR = [int(s) for s in input().split(" ")]


def calculate(n, arr, brr, crr):
    arr = sorted(arr)
    crr = sorted(crr)


    sum = 0
    for b in brr:
        s1 = bisect.bisect_right(arr,b-1)
        s2 = n - bisect.bisect_left(crr,b+1)
        sum = sum + s1 * s2

    print(sum)

calculate(N,ARR,BRR,CRR)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
ABC=[]
ABC.append(list(map(int,input().split())))
ABC.append(list(map(int,input().split())))
ABC.append(list(map(int,input().split())))
ABC[0].sort()
ABC[1].sort()
ABC[2].sort()


def bin_isOK(index,key,num):
    if ABC[num][index] >= key:
        return True
    else:
        return False


def binary_search(key,num):
    ng = -1
    ok = len(ABC[num])

    while abs(ok - ng) >1:
        mid = (ok + ng)//2

        if bin_isOK(mid,key,num):
            ok = mid
        else:
            ng = mid
    
    return ok
AonB=[0 for i in range(N)]
for i in range(N):
    AonB[i]=binary_search(ABC[1][i],0)

SAonB=[AonB[0]]

for i in range(1,N):
    SAonB.append(SAonB[i-1]+AonB[i])

ans=0
for i in range(N):
    num=binary_search(ABC[2][i],1)
    if num!=0:
        ans+=SAonB[num-1]
    
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):
    ans+=bisect.bisect_left(A,B[i])*(n-bisect.bisect_right(C,B[i]))
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())))

Upper = []
for i in B:##上の台について二分探索
    middle = bisect.bisect(A,i-1)
    Upper.append(middle)
for i in range(N-1):##累積和
    Upper[i+1] += Upper[i]
Upper = [0] + Upper

ans = 0
for i in C:
    bottom = bisect.bisect(B,i-1)
    ans += Upper[bottom]

print(ans)

Submission status: Accepted

Solution code:
from bisect import 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()

baseCnt = [0] * N
for idx, b in enumerate(B):
    ci = bisect_right(C, b)
    baseCnt[idx] = N - ci

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + baseCnt[i]

ans = 0
for a in A:
    bi = bisect_right(B, a)
    ans += S[N] - S[bi]

print(ans)

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()
i=0
k=0
ans=0
for j in range(n):
    while i<n and a[i]<b[j]:
        i+=1
    while k<n and c[k]<=b[j]:
        k+=1
    cnti=0
    cntk=0
    if i==n:
        cnti+=n
    else:
        cnti+=(i)
    if k<n:
        cntk+=(n-1-k+1)
    ans+=cnti*cntk
print(ans)

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()
ans = 0
for j in B:
    OK = -1
    NG = N
    while abs(OK-NG) > 1:
        mid = (OK + NG) // 2
        if A[mid] < j:
            OK = mid
        else:
            NG = mid
    A_ko = OK
    #print(OK)
        
    NG = -1
    OK = N
    while abs(NG-OK) > 1:
        mid = (NG + OK) // 2
        if C[mid] > j:
            OK = mid
        else:
            NG = mid
    
    C_ko = N - OK
    #print(C_ko)
    ans += (A_ko+1)*C_ko

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()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
ans = 0
for i in range(len(B2)):
    X = B2[i]
    l = bisect.bisect_left(A2,X)
    h = len(C2)-bisect.bisect_right(C2,X)
    #print(l,h)
    ans += l*h
print(ans)

Submission status: Accepted

Solution code:
import bisect

if __name__ == "__main__":
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    BB = []
    CC = []

    # print(A)
    # print(B)
    # print(C)
    # print('-------')

    cnt = 0

    for i in range(N):
        b = B[i]
        a_index = bisect.bisect_left(A, b)
        if i == 0:
            BB.append(a_index)
        else:
            BB.append(BB[i-1] + a_index)

    for i in range(N):
        c = C[i]
        b_index = bisect.bisect_left(B, c)
        if b_index == 0:
            CC.append(0)
            continue
        if i == 0:
            CC.append(BB[b_index - 1])
        else:
            CC.append(CC[i-1] + BB[b_index - 1])

    # print(BB)
    # print(CC)

    print(CC[-1])

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())))
count = 0
# ソートして
for b in B:
  upeer_b = N - bisect.bisect_right(C, b)
  downer_b = bisect.bisect_left(A, b)
  count += upeer_b * downer_b

# for c in C:
#   under_c = bisect.bisect_left(B, c)
#   for b in B[:under_c]:
#     under_b = bisect.bisect_left(A, b)
#     count += under_b

print(count)

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()

result = 0
for i in range(N):
    target = B[i]
    a_num = bisect.bisect_left(A, target)
    b_num = len(C)-bisect.bisect_right(C, target)
    result += a_num*b_num
print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))

b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
#print(a)
#print(b)
#print(c)
c_count=[]#cから行けるところの回数
b_count=[]#bから行けるところの回数

j=0
count=0
for i in range(n):#cから行けるところの回数
    for j in range(count,n):
        
        if b[j]<c[i]:
 #           print("dfghj")
            count+=1
        else:
  #          print("GHJK")
            break
    c_count.append(count)

count=0

for i in range(n):#bから行けるところの回数
    for j in range(count,n):
        if a[j]<b[i]:
            count+=1
        else:
            break
    b_count.append(count)

ans=0
#print(b_count)
#print(c_count)
for i in range(1,n):
    b_count[i]+=b_count[i-1]
#print(b_count)

for i in range(n):
    if 0<=c_count[i]-1:
        ans+=b_count[c_count[i]-1]

print(ans)

#print(b_count)
#print(c_count)

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()

#bisect_left:keyを挿入できる最小のindex
#bisect_right:keyを挿入できる最大のindex
ans = 0
for i in range(N):
    b_l,b_r = bisect_left(A,B[i]),N-bisect_right(C,B[i])
    ans += (b_l)*(b_r)
print(ans)

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()

def b_search_l(B,key):
    #key < B[s]を満たすsの個数
    if key < B[0]:
        return N
    elif key >= B[N-1]:
        return 0
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] <= key and key < B[mid+1]:
                return N-(mid+1)
            elif B[mid] > key:
                right = mid
            else:
                left = mid

def b_search_r(B,key):
    #key > B[t]を満たすtの個数
    if B[0] >= key:
        return 0
    elif B[N-1] < key:
        return N
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] < key and key <= B[mid+1]:
                return mid+1
            elif B[mid] >= key:
                right = mid
            else:
                left = mid

#b_l:keyより多い奴の個数
#b_r:key未満の奴の個数
ans = 0
for i in range(N):
    b_l,b_r = b_search_l(C,B[i]),b_search_r(A,B[i])
    ans += (b_l)*(b_r)
print(ans)

Submission status: Accepted

Solution code:

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

from bisect import bisect_left, bisect_right

res = 0
for b in B:
    res += bisect_left(A, b) * (N - bisect_right(C, b))
print(res)

Submission status: Accepted

Solution code:
from bisect import 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())))

cnt = [0] * N
for i in range(N):
    cnt[i] = N - bisect_right(C, B[i])

cumsum = [0] * (N + 1)
for i in range(N):
    cumsum[i + 1] = cumsum[i] + cnt[N - i - 1]
    
res = 0
for i in range(N):
    res += cumsum[N - bisect_right(B, A[i])]
print(res)

Submission status: Accepted

Solution code:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = np.array(readline().split(), dtype=np.int64)
    B = np.array(readline().split(), dtype=np.int64)
    C = np.array(readline().split(), dtype=np.int64)

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

    A_bisect = np.searchsorted(A, B, side="left")
    C_bisect = np.searchsorted(C, B, side="right")

    ans = A_bisect * (N - C_bisect)
    print(ans.sum())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    C = [int(i) for i in readline().split()]

    A = np.array(sorted(A), dtype=np.int64)
    B = np.array(sorted(B), dtype=np.int64)
    C = np.array(sorted(C), dtype=np.int64)

    A_bisect = np.searchsorted(A, B, side="left")
    C_bisect = np.searchsorted(C, B, side="right")

    ans = A_bisect * (N - C_bisect)
    print(ans.sum())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    C = [int(i) for i in readline().split()]

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

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

    print(ans)


if __name__ == "__main__":
    main()