Submission #1368039

#TimeUsernameProblemLanguageResultExecution timeMemory
1368039ap0100Inflation (EGOI23_inflation)C++20
33 / 100
82 ms13676 KiB
//A1-Inflation ('23 EGOI)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

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

    int n, q;
    cin >> n;
    unordered_map<ll, ll> freq;
    ll p, sum=0;
    for (int i=0; i<n; i++) {
        cin >> p;
        sum+=p;
        freq[p]++; //how many dishes have the price p
    }

    cin >> q;
    string s;
    int offset=0;
    vector<ll> res(q);
    for (int i=0; i<q; i++) {
        cin >> s;
        ll x,y;
        if (s=="INFLATION") {
            cin >> x;
            offset+=x;
            sum+=n*x;
        }else {
            cin >> x >> y; //x is the real/current value of some prices, but in freq we store the original values: real=stored+offset
            //to access the proper real x price, we need to access the proper stored, so stored=real-offset=x-offset and when chaning with y, change should be y-offset
            x-=offset; y-=offset;
            if (freq[x]>0) { //check if there even are prices with the wanted value
                sum+=(y-x)*freq[x];
                freq[y]+=freq[x]; //swtich them, now the value is y for all prices that were before x
                freq.erase(x); //remove x, there aren't any x valued dishes now
            }
        }
        res[i]=sum;
    }

    for (auto r: res) cout << r << '\n';


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