专栏文章

题解:AT_abc417_b Search and Delete

AT_abc417_b题解参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miok2kju
此快照首次捕获于
2025/12/02 20:29
3 个月前
此快照最后确认于
2025/12/02 20:29
3 个月前
查看原文
先开一个 map 存原数列中每个数出现的个数。对于每一个删数操作,判断数列中是否还有该数,如果有就将 map 中该数对应的值减一。最后遍历 map,同时输出即可。因为使用的是 map,所以最后的输出保证了是有序的。
CPP
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int n, m;
map <int, int> cnt;

int main(){
	
	ios :: sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1, x; i <= n; i++) cin >> x, cnt[x]++;
	for(int i = 1, x; i <= m; i++){
		cin >> x;
		if(cnt[x]) cnt[x]--;
	}
	auto it = cnt.begin();
	while(it != cnt.end()){
		for(int i = 1; i <= (*it).second; i++)
			cout << (*it).first << ' ';
		it++;
	}
	
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...