Submission #14550525


Source Code Expand

Copy
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = tuple(map(int, readline().split()))
Q = int(readline())
m = map(int, read().split())

counter = defaultdict(int)
for x in A:
    counter[x] += 1

total = sum(A)
for b, c in zip(m, m):
    total += (c - b) * counter[b]
    counter[c] += counter[b]
    counter[b] = 0
    print(total)

Submission Info

Submission Time
Task D - Replacing
User maspy
Language Python (3.8.2)
Score 400
Code Size 481 Byte
Status
Exec Time 200 ms
Memory 34580 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1.txt, sample2.txt, sample3.txt
All 400 / 400 sample1.txt, sample2.txt, sample3.txt, test1.txt, test2.txt, test3.txt, test4.txt, test5.txt, test6.txt, test7.txt, test8.txt, test9.txt
Case Name Status Exec Time Memory
sample1.txt 28 ms 9452 KB
sample2.txt 25 ms 9224 KB
sample3.txt 22 ms 9320 KB
test1.txt 127 ms 17188 KB
test2.txt 125 ms 16960 KB
test3.txt 165 ms 24324 KB
test4.txt 191 ms 29368 KB
test5.txt 161 ms 22596 KB
test6.txt 173 ms 27044 KB
test7.txt 191 ms 29376 KB
test8.txt 200 ms 34252 KB
test9.txt 197 ms 34580 KB