Advertisement
EvilingDark

Failed case #7/17: unknown signal 11

Feb 19th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <deque>
  2. #include <iostream>
  3. #include <map>
  4. #include <set>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. struct Client {
  10. Client(int32_t client_, int16_t room_count_)
  11. : client { client_ }
  12. , room_count { room_count_ }
  13. {
  14. }
  15. int32_t client = -1;
  16. int16_t room_count = -1;
  17. };
  18.  
  19. class Booking {
  20. public:
  21. void BOOK(const int64_t time,const string& hotel_name,const int32_t client_id,const int16_t room_count)
  22. {
  23. current_time = time;
  24. if (data_hotels.find(hotel_name) == data_hotels.end()) {
  25. data_hotels[hotel_name] = data_hotels.size();
  26. data_time.push_back({ { time, Client(client_id, room_count) } });
  27. } else {
  28. const int32_t time_id = data_hotels[hotel_name];
  29. data_time[time_id].push_back({ time, Client(client_id, room_count) });
  30. }
  31. }
  32.  
  33. int32_t CLIENTS(const string& hotel_name)
  34. {
  35. try {
  36. return count_clientsOrRooms(data_hotels.at(hotel_name));
  37. } catch (out_of_range&) {
  38. return 0;
  39. }
  40. }
  41.  
  42. int32_t ROOMS(const string& hotel_name)
  43. {
  44. try {
  45. return count_clientsOrRooms(data_hotels.at(hotel_name), true);
  46. } catch (out_of_range&) {
  47. return 0;
  48. }
  49. }
  50.  
  51. private:
  52. int64_t current_time = -2000000000000000001;
  53. map<string, int32_t> data_hotels; //hotel, hotel_id
  54. vector<deque<pair<int64_t, Client>>> data_time; //[hotel_id] time,(client,room_count)
  55.  
  56. int32_t count_clientsOrRooms(const int32_t time_id, const bool check = false)
  57. {
  58. int64_t minTime = current_time - 86399;
  59. auto& foundData = data_time.at(time_id);
  60. while (foundData.begin()->first < minTime)
  61. foundData.pop_front();
  62. if (foundData.empty())
  63. return 0;
  64. int32_t count_rooms = 0;
  65. set<int32_t> count_clients;
  66. for (int i = 0; i < foundData.size(); ++i) {
  67. if (check)
  68. count_rooms += foundData[i].second.room_count;
  69. else
  70. count_clients.emplace(foundData[i].second.client);
  71. }
  72. return check ? count_rooms : count_clients.size();
  73. }
  74. };
  75.  
  76. int main()
  77. {
  78. ios::sync_with_stdio(false);
  79. cin.tie(nullptr);
  80.  
  81. Booking manager;
  82.  
  83. int query_count;
  84. cin >> query_count;
  85.  
  86. for (int query_id = 0; query_id < query_count; ++query_id) {
  87. string query_type;
  88. cin >> query_type;
  89. switch (query_type[0]) {
  90. case 'B': {
  91. int64_t time;
  92. string hotel_name;
  93. int32_t client_id;
  94. int16_t room_count;
  95. cin >> time >> hotel_name >> client_id >> room_count;
  96. manager.BOOK(time, hotel_name, client_id, room_count);
  97. break;
  98. }
  99. case 'C': {
  100. string hotel_name;
  101. cin >> hotel_name;
  102. cout << manager.CLIENTS(hotel_name) << '\n';
  103. break;
  104. }
  105. case 'R': {
  106. string hotel_name;
  107. cin >> hotel_name;
  108. cout << manager.ROOMS(hotel_name) << '\n';
  109. break;
  110. }
  111. }
  112. }
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement