Galebickosikasa

Untitled

May 30th, 2021 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <map>
  5. #include <string>
  6. #include <vector>
  7. #include <set>
  8. #include <unordered_map>
  9. #include <queue>
  10.  
  11. using namespace std;
  12.  
  13. #define int int64_t
  14.  
  15. class HotelManager {
  16. private:
  17.     class Hotel {
  18.     public:
  19.         void book (int time, int client_id, int room_count) {
  20.             booked += room_count;
  21.             clients.push ({client_id, room_count, time});
  22.             ++count[client_id];
  23.         }
  24.  
  25.         int Clients () {
  26.             check ();
  27.             return (int)count.size ();
  28.         }
  29.  
  30.         int Rooms () {
  31.             check ();
  32.             return booked;
  33.         }
  34.     private:
  35.         struct Order {
  36.             int client_id, room_count, time;
  37.         };
  38.         queue<Order> clients;
  39.         unordered_map <int, int> count;
  40.         int booked = 0;
  41.  
  42.         void check () {
  43.             while (!clients.empty () && clients.front ().time <= current_time - 86400) {
  44.                 auto ptt = clients.front ();
  45.                 clients.pop ();
  46.                 booked -= ptt.room_count;
  47.                 --count[ptt.client_id];
  48.                 if (count[ptt.client_id] == 0) count.erase (ptt.client_id);
  49.             }
  50.         }
  51.     };
  52.  
  53.     map <string, Hotel> hotels;
  54. public:
  55.     inline static int current_time = 0;
  56.  
  57.     void book (int time, const string& hotel_name, int client_id, int room_count) {
  58.         hotels[hotel_name].book (time, client_id, room_count);
  59.         current_time = time;
  60.     }
  61.     int clients (const string& hotel_name) {
  62.         return hotels[hotel_name].Clients();
  63.     }
  64.     int rooms (const string& hotel_name) {
  65.         return hotels[hotel_name].Rooms();
  66.     }
  67. };
  68.  
  69. signed main() {
  70.     HotelManager hm;
  71.     int q;
  72.     cin >> q;
  73.     while (q--) {
  74.         string t, hotel_name;
  75.         cin >> t;
  76.         if (t[0] == 'B') {
  77.             int time, client_id, room_count;
  78.             cin >> time >> hotel_name >> client_id >> room_count;
  79.             hm.book(time, hotel_name, client_id, room_count);
  80.         } else if (t[0] == 'C') {
  81.             cin >> hotel_name;
  82.             cout << hm.clients(hotel_name) << '\n';
  83.         } else if (t[0] == 'R') {
  84.             cin >> hotel_name;
  85.             cout << hm.rooms(hotel_name) << '\n';
  86.         }
  87.     }
  88.  
  89. }
  90.  
Add Comment
Please, Sign In to add comment