AtCoder Beginner Contest: D Question Answers Python

AtCoder Beginner Contest 171

Use collections.defauldict (int) to count the number of each number

import collections
 
N = int(input())
A = sorted(map(int, input().split()))
 
cnt = collections.defaultdict(int)
for a in A:
    cnt[a] += 1
ans = sum(A)
 
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * cnt[B]
    cnt[C] += cnt[B]
    cnt[B] = 0

Will be added later

Recommended Posts

AtCoder Beginner Contest: D Question Answers Python
Atcoder Beginner Contest 152 Kiroku (python)
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Beginner Contest 177
AtCoder Beginner Contest 172
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
Review of AtCoder Beginner Contest 159, up to question E (Python)
Review of AtCoder Beginner Contest 163, up to question E (Python)
Review of AtCoder Beginner Contest 164, up to question E (Python)
Review of AtCoder Beginner Contest 162, up to question E (Python)
Review of AtCoder Beginner Contest 154, up to question E (Python)
Review of AtCoder Beginner Contest 153, up to question E (Python)
Review of AtCoder Beginner Contest 160, up to question E (Python)
Review of AtCoder Beginner Contest 167, up to question E (Python)
Review of AtCoder Beginner Contest 157, up to question E (Python)
Review of AtCoder Beginner Contest 161, up to question E (Python)
Review of AtCoder Beginner Contest 155, up to question E (Python)
Review of AtCoder Beginner Contest 156, up to question E (Python)
Review of AtCoder Beginner Contest 166, up to question E (Python)
Review of AtCoder Beginner Contest 165, up to question E (Python)
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 181 Note
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 164 Review
AtCoder Beginner Contest 169 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 182 Review
AtCoder Beginner Contest 180 Review
AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Beginner Contest 179 Review
Solve AtCoder Beginner Contest 100-102
AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 184 Note
AtCoder Beginner Contest 175 Review
AtCoder Beginner Contest 174 Review
AtCoder Beginner Contest 153 Review
AtCoder Beginner Contest 156 Review
AtCoder Beginner Contest 161 Review
AtCoder Beginner Contest 170 Review
AtCoder Beginner Contest 165 Review
AtCoder Beginner Contest 173 Review
AtCoder Beginner Contest 188 Note
AtCoder Beginner Contest 155 Review
AtCoder Beginner Contest 162 Review
Solve AtCoder Beginner Contest 170 D --Not Divisible (ABC170D) with python (Eratosthenes sieve)
AtCoder Beginner Contest 175 Virtual entry
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 151 Participation Report
AtCoder Beginner Contest 176 Participation Report