Advertisement
smatskevich

KolyaAndDCs

May 26th, 2023
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <iomanip>
  5. #include <iostream>
  6. #include <limits>
  7. #include <map>
  8. #include <queue>
  9. #include <set>
  10. #include <stack>
  11. #include <string>
  12. #include <tuple>
  13. #include <unordered_map>
  14. #include <unordered_set>
  15. #include <vector>
  16.  
  17. using namespace std;
  18. typedef long long ll;
  19. const double eps = 1e-10;
  20. const int mod = 1000000007;
  21.  
  22. int main() {
  23.   ll n, m, q; cin >> n >> m >> q;
  24.   vector<ll> resets(n);
  25.   vector<unordered_set<int>> broken_servers(n);
  26.   set<pair<ll, int>> answ;
  27.   for (int i = 0; i < n; ++i)
  28.     answ.insert(make_pair(0, i));
  29.  
  30.   for (int i = 0; i < q; ++i) {
  31.     string query; cin >> query;
  32.     if (query == "RESET") {
  33.       int d; cin >> d; --d;
  34.       answ.erase(make_pair(resets[d] * (m - broken_servers[d].size()), d));
  35.       broken_servers[d].clear();
  36.       ++resets[d];
  37.       answ.insert(make_pair(resets[d] * m, d));
  38.     } else if (query == "DISABLE") {
  39.       int d, s; cin >> d >> s; --d; --s;
  40.       if (!broken_servers[d].contains(s)) {
  41.         answ.erase(make_pair(resets[d] * (m - broken_servers[d].size()), d));
  42.         broken_servers[d].insert(s);
  43.         answ.insert(make_pair(resets[d] * (m - broken_servers[d].size()), d));
  44.       }
  45.     } else if (query == "GETMIN") {
  46.       cout << answ.begin()->second + 1 << "\n";
  47.     } else if (query == "GETMAX") {
  48.       auto it = answ.lower_bound(make_pair(answ.rbegin()->first, 0));
  49.       cout << it->second + 1 << "\n";
  50.     }
  51.   }
  52.   return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement