2353.cpp (836B)
1 class FoodRatings { 2 unordered_map<string, set<pair<int, string>>> order; 3 unordered_map<string, string> category; 4 unordered_map<string, int> rating; 5 6 public: 7 FoodRatings(const vector<string> &foods, const vector<string> &cuisines, const vector<int> &ratings) { 8 for (int i = 0; i < foods.size(); i++) { 9 order[cuisines[i]].emplace(-ratings[i], foods[i]); 10 category.emplace(foods[i], cuisines[i]); 11 rating.emplace(foods[i], ratings[i]); 12 } 13 } 14 15 void changeRating(const string &food, int newRating) { 16 auto &st = order[category[food]]; 17 st.erase(st.find({-rating[food], food})); 18 rating[food] = newRating; 19 st.emplace(-rating[food], food); 20 } 21 22 string highestRated(const string &cuisine) { return order[cuisine].begin()->second; } 23 };