题解-python-CodeForces 227B

用hash解决。我python代码消耗很多内存,好在代码比C++短很多

n = int(raw_input())
mylist = raw_input().split(' ')
i = 0
zid = {}
for x in mylist:
    zid[x] = i
    i += 1
q = int(raw_input())
m = raw_input().split(' ')
ans1 = 0
ans2 = 0
for y in m:
    tmp = zid[y]
    ans1 += tmp + 1
    ans2 += n - tmp
print ans1, ans2

你可能感兴趣的:(codeforces)