Advertisement
pb_jiang

ABC306E WA

Jun 18th, 2023
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  8.  
  9. using ll = long long;
  10. using pii = pair<int, int>;
  11. using pll = pair<ll, ll>;
  12. using vl = vector<ll>;
  13. using vi = vector<int>;
  14.  
  15. int main(int argc, char **argv)
  16. {
  17.     cin.tie(nullptr)->sync_with_stdio(false);
  18.     int n, k, q, x, y;
  19.     cin >> n >> k >> q;
  20.     ll acc = 0;
  21.     using a2i = array<int, 2>;
  22.     set<a2i> ms;
  23.     for (int i = 0; i < n; ++i)
  24.         ms.insert({0, i});
  25.     auto bar = ms.end();
  26.     for (int i = 0; i < k; ++i)
  27.         bar = prev(bar);
  28.  
  29.     vi a(n + 1);
  30.     for (int i = 0; i < q; ++i) {
  31.         cin >> x >> y;
  32.         if (k != n) {
  33.             a2i old_v = {a[x], x}, new_v = {y, x};
  34.             a[x] = y;
  35.             if (old_v >= *bar)
  36.                 bar = prev(bar), acc = acc - old_v[0] + bar->at(0);
  37.             ms.erase(old_v);
  38.             ms.insert(new_v);
  39.             if (new_v > *bar)
  40.                 acc = acc + new_v[0] - bar->at(0), bar = next(bar);
  41.         } else {
  42.             acc = acc + y - a[x];
  43.             a[x] = y;
  44.         }
  45.  
  46.         cout << acc << endl;
  47.     }
  48.     return 0;
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement