1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| class MovieRentingSystem { public: map<tuple<int,int>, int> vis; priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> jc; priority_queue<tuple<int,int>, vector<tuple<int,int>>, greater<tuple<int,int>>> wj[300005]; MovieRentingSystem(int n, vector<vector<int>>& entries) { for(auto &entry: entries) { int shop = entry[0], movie = entry[1], price = entry[2]; vis[tuple(shop, movie)] = price; wj[movie].push(tuple(price, shop)); } } vector<int> search(int movie) { vector<int> ans;
vector<tuple<int,int>> tmp; map<tuple<int,int>, bool> book;
int cnt = 0; while(cnt < 5 && !wj[movie].empty()) { auto [price, shop] = wj[movie].top(); wj[movie].pop(); if(vis[tuple(shop, movie)] < 0 || book[tuple(shop, movie)] == true) { continue; } ++cnt; book[tuple(shop, movie)] = true; tmp.push_back(tuple(price, shop)); ans.push_back(shop); } for(auto t: tmp) { wj[movie].push(t); } return ans; } void rent(int shop, int movie) { int price = vis[tuple(shop, movie)]; vis[tuple(shop, movie)] = -price;
jc.push(tuple(price, shop, movie)); } void drop(int shop, int movie) { int price = vis[tuple(shop, movie)]; vis[tuple(shop, movie)] = -price; wj[movie].push(tuple(-price, shop)); } vector<vector<int>> report() { vector<vector<int>> ans; vector<int> t(2); map<tuple<int,int>, bool> book; vector<tuple<int,int,int> > tmp; int cnt = 0; while(cnt < 5 && !jc.empty()) { auto [price, shop, movie] = jc.top(); jc.pop(); if(vis[tuple(shop, movie)] > 0 || book[tuple(shop, movie)] == true) { continue; } ++cnt; tmp.push_back(tuple(price, shop, movie)); book[tuple(shop, movie)] = true; t[0] = shop, t[1] = movie; ans.push_back(t); } for(auto tt: tmp) { jc.push(tt); } return ans; } };
|