题面:Luogu2073
有意思,上一篇博客采来的花都送掉了2333
这题做法太多啦hhh
对于这种用码量来征服的题目,我的决定是:
Standard Template Library!
像这种乱七八糟的操作,平衡树随便搞搞,set也能
我们开结构体set,以价格为关键字
插入的时候开个数组记录一下该价格有没有放过
弹出的时候记得更新一下这个数组,都清清空(我被坑到了QAQ)
最小的就是begin()这个位置,最大的是end()的前一个迭代器位置!!!(记得前一个!C++容器的end()位置都是没有东西的)
最后整个set扫一遍,统计答案就好了
代码奇短(相对于写线段树平衡树的来说)
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
using namespace std;
struct ppap{int x,y;};
bool operator <(const ppap& a,const ppap& b){return a.y<b.y;}
set<ppap>a;
bool k[1000001];
int main()
{
set<ppap>::iterator i;//这是迭代器
while(1){
int p;scanf("%d",&p);
if(p==-1)break;i=a.end();
if(p==1){
int x,y;scanf("%d%d",&x,&y);
if(k[y])continue;k[y]=1;
a.insert((ppap){x,y});
}else if(p==2&&!a.empty())i--,k[i->y]=0,a.erase(i);//记得--!!!
else if(p==3&&!a.empty())k[a.begin()->y]=0,a.erase(a.begin());
}
int ans1=0,ans2=0;
for(i=a.begin();i!=a.end();i++)ans1+=i->x,ans2+=i->y;//扫一遍
printf("%d %d",ans1,ans2);
return 0;
}