Advertisement
erek1e

EGOI '23 - Inflation

Jul 21st, 2023
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  7.     int n; cin >> n;
  8.     map<long long, int> f;
  9.     long long sum = 0;
  10.     for (int i = 0; i < n; ++i) {
  11.         int x; cin >> x;
  12.         ++f[x], sum += x;
  13.     }
  14.  
  15.     long long offset = 0;
  16.     int q; cin >> q;
  17.     while (q--) {
  18.         string s; cin >> s;
  19.         if (s == "INFLATION") {
  20.             long long x; cin >> x;
  21.             offset += x;
  22.             sum += n*x;
  23.         } else {
  24.             long long x, y; cin >> x >> y;
  25.             x -= offset, y -= offset;
  26.             if (f.count(x)) {
  27.                 int c = f[x];
  28.                 f.erase(x);
  29.                 f[y] += c;
  30.                 sum += c*(y-x);
  31.             }
  32.         }
  33.         cout << sum << '\n';
  34.     }
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement