CCF 201909-4 推荐系统

 

 

#include <cstdio>
#include <set>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
ll inf = (ll)1e9;
//关键点,用一个整数表示第几类编号为几的商品,方便处理排序,注意int有可能越界 
struct Node {
	ll type;
	ll id;
	int score;
	
	Node(ll type, ll id, int score): type(type), id(id), score(score) {}
	bool operator < (const Node& n1) const {
		if(n1.score != score) return score > n1.score;
		else if(n1.type != type) return type < n1.type;
		else return id < n1.id;
	}
};
unordered_map<ll, set<Node>::iterator> ma;
int num[55];
int main() {
	int m, n; scanf("%d %d", &m, &n);
	set<Node> s;
	for(int i = 1; i <= n; i ++) {
		ll id;
		int score; scanf("%lld %d", &id, &score);
		for(ll j = 0; j < m; j ++) {
			ll temp = j * inf + id;
			ma[temp] = s.insert(Node(j, id, score)).first; //s.insert()返回 pair<set<Node>::iterator, bool>
		}
	}
	
	int op; scanf("%d", &op);
	while(op --) {
		int t; scanf("%d", &t);
		if(t == 3) {
			vector<vector<int> > ans(m);	//用set报错暂时还没想明白 
			int k; scanf("%d", &k);
			for(int i = 0; i < m; i ++) {
				scanf("%d", &num[i]);
			}
			
			for(auto& u : s) {
				if(ma.count(u.type * inf + u.id) && num[u.type]) {
					num[u.type] --;
					k --;
					ans[u.type].push_back(u.id);
					if(k == 0) break;
				}
			}
			
			for(int i = 0; i < m; i ++) {
				if(!ans[i].empty()) {
					int first = ans[i][0];
					for(auto& p : ans[i]) {
						if(p != first) printf(" %d", p);
						else printf("%d", p);
					}
					printf("\n");
				}else {
					printf("-1\n"); 
				}
			}
		}else if(t == 2) {
			ll type, id; scanf("%lld %lld", &type, &id);
			ll temp = type * inf + id;
			s.erase(ma[temp]);
			ma.erase(temp);
		}else {
			ll type, id;
			int score; scanf("%lld %lld %d", &type, &id, &score);
			ll temp = type * inf + id;
			ma[temp] = s.insert(Node(type, id, score)).first;
		}
	}
	return 0;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值