E - 小埋的steam愿望单
Time Limit: 2000 MS Memory Limit: 64 MB
Submit Status
小埋有一个steam愿望单,上面记载着她想买的游戏!现在小埋有以下 nn 个操作:
1 x y1 x y 添加一个价格为 yy 名字为 xx 的游戏加入愿望单
2 x2 x 删除名字为 xx 的游戏
3 x y3 x y 名字为 xx 的游戏价格调整为 yy
4 x4 x xx 为 11 输出最便宜的游戏的名字(如果有多个同价格游戏输出字典序最小的),xx 为 22 输出最贵的游戏(如果有多个同价格游戏输出字典序最大的)
不合法的情况请忽略该操作
不合法的情况请忽略该操作
不合法的情况请忽略该操作
Input
第一行一个n(1≤n≤1e5)n(1≤n≤1e5) 接下来 nn 行 每行一个 pp 表示操作类型 接下来根据操作类型跟一个或两个数字( xx 只包括大小写字母和下划线并不超过25个字符,1≤y≤1e91≤y≤1e9)
Output
对于每个查询,输出一行对应游戏的名字
Sample input and output
Sample Input | Sample Output |
---|---|
8 1 slay_the_spire 60 1 dark_soul_III 118 1 The_Binding_of_Isaac 58 1 Age_of_Empires_II 88 4 1 3 dark_soul_III 57 4 1 4 2 |
The_Binding_of_Isaac dark_soul_III Age_of_Empires_II |
7 4 1 1 I 100 1 II 150 1 I 200 4 1 2 III 3 IV 600 |
I |
#include<iostream> #include<algorithm> #include<utility> #include<map> #include<set> #include<string> using namespace std; set< pair<int,string> > PriceandName; map< string,int > price1; int main() { ios::sync_with_stdio(false); int n; int d; int x; string name; int price; cin>>n; while(n--) { cin >> d; if(d==1) { cin >> name >> price; if(price1[name]!=0) { continue; } else { price1[name]=price; PriceandName.insert(pair<int,string>{price,name}); } } else if(d==2) { cin >> name; if(price1[name]==0) { continue; } else { PriceandName.erase(pair<int,string>{price1[name],name}); price1[name]=0; } } else if(d==3) { cin >> name >> price; if(price1[name]==0) continue; else { PriceandName.erase(pair<int,string>{price1[name],name}); price1[name]=price; PriceandName.insert(pair<int,string>{price,name}); } } else if(d==4) { cin >> x; if(PriceandName.empty()) { continue; } if(x==1) { auto begin = PriceandName.begin(); cout << (*begin).second <<endl; } else { auto end = PriceandName.end(); cout << (*(--end)).second<<endl; } } } return 0; }