#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<map>
using namespace std;
class MovieRentingSystem {
public:
set<pair<int, int>> mv[100001];
set<pair<int, pair<int, int>>> rt;
map<pair<int, int>, int> prc;
MovieRentingSystem(int n, int m,vector<vector<int>>& entries) {
cout<<"YES"<<endl;
for (int i = 0; i <m; i++) {
cout<<i<<endl;
int x=entries[i][0], y=entries[i][1], z=entries[i][2];
prc[make_pair(x, y)] = z;
mv[y].insert(make_pair(z, x));
}
}
void search_(int movie) {
auto it = mv[movie].begin();
for (size_t i=0; i<5 && it!=mv[movie].end(); i++,it++) cout<<it -> second<<" ";
cout<<endl;
}
void rent(int shop, int movie) {
int price = prc[make_pair(shop, movie)];
mv[movie].erase(make_pair(price, shop));
rt.insert(make_pair(price, make_pair(shop, movie)));
}
void drop(int shop, int movie) {
int price = prc[make_pair(shop, movie)];
mv[movie].insert(make_pair(price, shop));
rt.erase(make_pair(price, make_pair(shop, movie)));
}
void report() {
auto it = rt.begin();
for (int i=0; i<5 && it!=rt.end(); i++,it++) cout<<(it->second).first<<" "<<(it->second).second<<endl;
}
};
int main(){
int n,m;
string str;
cin>>n>>m;
vector<vector<int>>entries(m,vector<int>(3));
for(int i=1;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
vector<int>tmp;
tmp.push_back(a);
tmp.push_back(b);
tmp.push_back(c);
entries.push_back(tmp);
}
MovieRentingSystem movieRentingSystem(n,m,entries);
while(cin>>str){
if(str=="search"){
int movie;
cin>>movie;
movieRentingSystem.search_(movie);
}
else if(str=="report")
{
movieRentingSystem.report();
}
else if(str=="drop")
{
int shop,movie;
cin>>shop>>movie;
movieRentingSystem.drop(shop,movie);
}
else
{
int shop,movie;
cin>>shop>>movie;
movieRentingSystem.rent(shop,movie);
}
}
return 0;
}
【无标题】whhy
最新推荐文章于 2024-08-22 23:21:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)