AT_abc298_c的题解
(一)
由于要从小到大输出,所以用两个二维优先队列 \(ans1\) 和 \(ans2\) 对应操作 \(2\) 和 \(3\)。
注意:操作三要去重!这里用 map 解决。
(二)
AC 代码(略卡常)。
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
priority_queue<int,vector<int>,greater<int> >ans1[200001],ans2[200001],t;
map<int,bool>mp[200001];
int m,n;
int main(){
scanf("%d%d",&n,&m);
while(m--){
int op,x,y;
scanf("%d",&op);
if(op==1){
scanf("%d%d",&x,&y);
ans1[y].push(x);
if(!mp[x][y])ans2[x].push(y),mp[x][y]=1;
}
if(op==2){
scanf("%d",&x);
t=ans1[x];
while(!t.empty()){
printf("%d ",t.top());
t.pop();
}
printf("\n");
}
if(op==3){
scanf("%d",&x);
t=ans2[x];
while(!t.empty()){
printf("%d ",t.top());
t.pop();
}
printf("\n");
}
}
return 0;
}

浙公网安备 33010602011771号