Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <queue>
- #include <map>
- #include <algorithm>
- #include <stdexcept>
- using namespace std;
- class BookManager {
- public:
- BookManager() {
- }
- void Book(const string& hotel_name, const long long& time,
- const int& client_id, const int& room_count) {
- last_time = time;
- rooms[hotel_name].push(make_pair(time, room_count));
- room_amount[hotel_name]+=room_count;
- clients_[hotel_name][client_id]+=room_count;
- //.push(make_pair(client_id, time));
- if(rooms[hotel_name].size() > 1) {
- long long current_time = rooms[hotel_name].back().first;
- while(rooms[hotel_name].front().first <= current_time - 86400) {
- /*for(auto& a : room_amount) {
- a.second-=rooms.at(a.first).front().second;
- }*/
- room_amount[hotel_name]-=rooms[hotel_name].front().second;
- clients_[hotel_name][client_id]-=rooms[hotel_name].front().second;
- if(clients_[hotel_name][client_id] == 0) {
- clients_[hotel_name].erase(client_id);
- }
- rooms[hotel_name].pop();
- }
- }
- }
- int Clients(const string& hotel_name) const {
- //vector<pair<long long, int>> v;
- //clients.at(hotel_name);
- try {
- return clients_.at(hotel_name).size();
- } catch(exception& e) {
- return 0;
- }
- }
- int Rooms(const string& hotel_name) {
- //if(room_amount[hotel_name] == 0) {return 0;}
- try {
- //if(rooms[hotel_name].size() > 0) {
- long long current_time = last_time;
- //cout << "really?" << rooms[hotel_name].front().first << ", " << current_time - 86400 << endl;
- while(rooms.at(hotel_name).front().first <= current_time - 86400) {
- //cout << hotel_name << "!" << endl;
- room_amount.at(hotel_name)-=rooms.at(hotel_name).front().second;
- rooms.at(hotel_name).pop();
- }
- //}
- return room_amount.at(hotel_name);
- } catch(exception& e) {
- return 0;
- }
- }
- private:
- map<string, queue<pair<long long, int>>> rooms;
- //map<string, queue<pair<long long, int>>> clients;
- map<string, map<int, int>> clients_;
- map<string, int> room_amount;
- long long last_time;
- //map<string, int> clients_amount;
- //int room_amount;
- //int clients_amount;
- };
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- BookManager bm;
- int query_count;
- cin >> query_count;
- for(int i = 0; i < query_count; ++i) {
- string query_type, hotel_name;
- cin >> query_type;
- if(query_type == "BOOK") {
- long long time;
- int client_id;
- int room_count;
- cin >> time >> hotel_name >> client_id >> room_count;
- bm.Book(hotel_name, time, client_id, room_count);
- } else if(query_type == "CLIENTS") {
- cin >> hotel_name;
- cout << bm.Clients(hotel_name) << endl;
- } else if(query_type == "ROOMS") {
- cin >> hotel_name;
- cout << bm.Rooms(hotel_name) << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement