Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cmath>
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- #include <set>
- #include <unordered_map>
- #include <queue>
- using namespace std;
- #define int int64_t
- class HotelManager {
- private:
- class Hotel {
- public:
- void book (int time, int client_id, int room_count) {
- booked += room_count;
- clients.push ({client_id, room_count, time});
- ++count[client_id];
- }
- int Clients () {
- check ();
- return (int)count.size ();
- }
- int Rooms () {
- check ();
- return booked;
- }
- private:
- struct Order {
- int client_id, room_count, time;
- };
- queue<Order> clients;
- unordered_map <int, int> count;
- int booked = 0;
- void check () {
- while (!clients.empty () && clients.front ().time <= current_time - 86400) {
- auto ptt = clients.front ();
- clients.pop ();
- booked -= ptt.room_count;
- --count[ptt.client_id];
- if (count[ptt.client_id] == 0) count.erase (ptt.client_id);
- }
- }
- };
- map <string, Hotel> hotels;
- public:
- inline static int current_time = 0;
- void book (int time, const string& hotel_name, int client_id, int room_count) {
- hotels[hotel_name].book (time, client_id, room_count);
- current_time = time;
- }
- int clients (const string& hotel_name) {
- return hotels[hotel_name].Clients();
- }
- int rooms (const string& hotel_name) {
- return hotels[hotel_name].Rooms();
- }
- };
- signed main() {
- HotelManager hm;
- int q;
- cin >> q;
- while (q--) {
- string t, hotel_name;
- cin >> t;
- if (t[0] == 'B') {
- int time, client_id, room_count;
- cin >> time >> hotel_name >> client_id >> room_count;
- hm.book(time, hotel_name, client_id, room_count);
- } else if (t[0] == 'C') {
- cin >> hotel_name;
- cout << hm.clients(hotel_name) << '\n';
- } else if (t[0] == 'R') {
- cin >> hotel_name;
- cout << hm.rooms(hotel_name) << '\n';
- }
- }
- }
Add Comment
Please, Sign In to add comment