Submission #1329826

#TimeUsernameProblemLanguageResultExecution timeMemory
1329826model_codeInflation (EGOI23_inflation)C++20
100 / 100
87 ms12944 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    unordered_map<long long, long long> freq;
    long long s = 0, g = 0;

    for (int i = 0; i < N; i++) {
        long long p;
        cin >> p;
        freq[p]++;
        s += p;
    }

    int Q;
    cin >> Q;

    for (int q = 0; q < Q; q++) {
        string type;
        cin >> type;
        if (type == "INFLATION") {
            long long x;
            cin >> x;
            g += x;
        } else {
            long long x, y;
            cin >> x >> y;
            x -= g;
            y -= g;
            if (x != y && freq.count(x) && freq[x] > 0) {
                s += freq[x] * (y - x);
                freq[y] += freq[x];
                freq.erase(x);
            }
        }
        cout << s + (long long)N * g << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...