ccf-201909-4 推荐系统

中等的模拟题,自己写的太搓了。

  1. 自己原来写了离散化,后来删了
  2. 原来超时,后来加了一个很小的优化
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 3e5+10;
int a[maxn];
int price[200000];
unordered_map mp;
int m, n;
int col;

int b[maxn];
int op_num;

struct Node{
    int id;
    int price;
    int type;
    bool operator < (const Node &b) const {
        if(price!=b.price) return price>b.price;
        else if(type != b.type) return type st[55];
int k[60];

void add(int type, int commodity, int score){
    st[type].insert(Node{commodity, score, type});
}

void del(int type, int commodity){
    if(st[type].count(Node{commodity, mp[commodity], type})!=0)
        st[type].erase(Node{commodity, mp[commodity], type});

}

void process(int lim, int type){
    if(st[type].empty()){
        cout<<-1<<"\n";
        return ;
    }
    set::iterator it = st[type].begin();
    for(; it!=st[type].end(); it++){
        lim--;
        if(lim==0){
            cout<id<<"\n";
            break;
        }
        else {
            cout<id<<" ";
        }
    }
}



int main(){
    ios::sync_with_stdio(false);
    cin>>m>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i]>>price[i];
        mp[a[i]] = price[i];
    }

    for(int i=0; i>op_num;
    int op, type, commodity, score;

    for(int i=1; i<=op_num; i++){
        cin>>op;
        if(op == 1){
            cin>>type>>commodity>>score;
            mp[commodity] = score;
            add(type, commodity, score);
        }
        else if(op == 2){
            cin>>type>>commodity;
            del(type, commodity);
        }
        else{
            int K;
            cin>>K;
            int tot = 0;
            for(int j=0; j>k[j], tot += k[j];
            if(K>=tot)
                for(int j=0; j pq;
                pq.clear();
                set::iterator it;
                for(int j=0; j ans[60];
                for(int j=0; j<60; j++) ans[j].clear();
                for(int j=0; j

你可能感兴趣的:(ccf-201909-4 推荐系统)