力扣2353.设计食物评分系统
-
懒删除堆
- 和2349.类似
-
class FoodRatings { unordered_map<string,pair<int,string>> fs; unordered_map<string, priority_queue<pair<int, string>, vector<pair<int, string>>, greater<>>> cs; public: FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) { for(int i=0;i<foods.size();i++) { auto &f = foods[i],&c = cuisines[i]; int r = ratings[i]; fs[f] = {r,c}; cs[c].emplace(-r,f); } } void changeRating(string food, int newRating) { auto &[r,c] = fs[food]; cs[c].emplace(-newRating,food); r = newRating; } string highestRated(string cuisine) { auto &q = cs[cuisine]; while(-q.top().first != fs[q.top().second].first) q.pop(); return q.top().second; } };