Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)



Fixed submission:
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''

    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]
    '''

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    # リスト内の要素数の更新
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)



Fixed submission:
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''

    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]
    '''

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    # リスト内の要素数の更新
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
import bisect

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    print(sum(A))



Fixed submission:
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''

    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]
    '''

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    # リスト内の要素数の更新
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys

readline = sys.stdin.readline

N = int(input())
A = np.array(readline().split(), np.int64)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

for q in range(Q):
    A = [BC[q][1] if x==BC[q][0] else x for x in A]
    print(sum(A))

Fixed submission:
import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''

    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]
    '''

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    # リスト内の要素数の更新
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)