Untitled

 avatar
unknown
plain_text
a year ago
7.8 kB
1
Indexable
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

#define CMD_INIT				(100)
#define CMD_WRITE_MESSAGE		(200)
#define CMD_COMMENT_TO			(300)
#define CMD_ERASE				(400)
#define CMD_GET_BEST_MESSAGES	(500)
#define CMD_GET_BEST_USERS		(600)

#define MAXL	(10)	

extern void init();
extern int writeMessage(char mUser[], int mID, int mPoint);
extern int commentTo(char mUser[], int mID, int mTargetID, int mPoint);
extern int erase(int mID);
extern void getBestMessages(int mBestMessageList[]);
extern void getBestUsers(char mBestUserList[][MAXL + 1]);

static int mstrcmp(char a[], char b[])
{
	int idx = 0;
	while (a[idx] != '\0' && a[idx] == b[idx])
		++idx;
	return a[idx] - b[idx];
}

static bool run()
{
	int Q;
	int mID, mTargetID, mPoint;
	char mUser[MAXL + 1];
	char mBestUserList[5][MAXL + 1];
	int mBestMessageList[5];

	int ret = -1, ans;

	scanf("%d", &Q);

	bool okay = false;

	for (int q = 0; q < Q; ++q)
	{
		int cmd;
		scanf("%d", &cmd);
		switch(cmd)
		{
		case CMD_INIT:
			init();
			okay = true;
			break;
		case CMD_WRITE_MESSAGE:
			scanf("%s %d %d", mUser, &mID, &mPoint);
			ret = writeMessage(mUser, mID, mPoint);
			scanf("%d", &ans);
			if (ret != ans)
				okay = false;
			break;
		case CMD_COMMENT_TO:
			scanf("%s %d %d %d", mUser, &mID, &mTargetID, &mPoint);
			ret = commentTo(mUser, mID, mTargetID, mPoint);
			scanf("%d", &ans);
			if (ret != ans)
				okay = false;
			break;
		case CMD_ERASE:
			scanf("%d", &mID);
			ret = erase(mID);
			scanf("%d", &ans);
			if (ret != ans)
				okay = false;
			break;
		case CMD_GET_BEST_MESSAGES:
			getBestMessages(mBestMessageList);
			for (int i = 0; i < 5; ++i)
			{
				scanf("%d", &ans);
				if (mBestMessageList[i] != ans)
					okay = false;
			}
			break;
		case CMD_GET_BEST_USERS:
			getBestUsers(mBestUserList);
			for (int i = 0; i < 5; ++i)
			{
				scanf("%s", mUser);
				if (mstrcmp(mBestUserList[i], mUser) != 0)
					okay = false;
			}
			break;
		default:
			okay = false;
			break;
		}
	}

	return okay;
}

int main()
{
	setbuf(stdout, NULL);
	freopen("input.txt", "r", stdin);

	int TC, MARK;

	scanf("%d %d", &TC, &MARK);
	for (int tc = 1; tc <= TC; ++tc)
	{
		int score = run() ? MARK : 0;
		printf("#%d %d\n", tc, score);
	}

	return 0;
}

//////
#define MAXL    (10)
   
#include<string>
#include<string.h>
#include<set>
#include<vector>
#include<unordered_map>
using namespace std;
 
unordered_map<string, int> usermap;
unordered_map<int, int> msgmap;
struct US{
    string name;
    int point;
}users[10001];
struct MS{
    int id,par,point,root,uid;
    bool isvalid;
}msgs[50001];
 
struct cmpu{
    bool operator()(int a,int b)const{
        if(users[a].point!= users[b].point)
            return users[a].point > users[b].point;
        else
            return users[a].name< users[b].name;
    }
};
struct cmpm{
    bool operator()(int a,int b)const{
        if(msgs[a].point!= msgs[b].point)
            return msgs[a].point > msgs[b].point;
        else
            return msgs[a].id< msgs[b].id;
    }
};
int uidx,midx;
set<int,cmpu> userset;
set<int,cmpm> msgset;
vector<int> msg_gr[50001];
void init(){
    uidx=midx=0;
    msgmap.clear();
    usermap.clear();
    userset.clear();
    msgset.clear();
    return;
}
int findpar(int id){
    while(msgs[id].par!=-1){
        id=msgs[id].par;
    }
    return id;
}
int update_user(char uname[],int point){
    if(usermap.find(uname)== usermap.end()){
        usermap[uname]=uidx;
        users[uidx].name=uname;
        users[uidx].point=0;
        uidx++;
    }
    int uid=usermap[uname];
    userset.erase(uid);
    users[uid].point+=point;
    userset.insert(uid);
    return uid;
}
int writeMessage(char mUser[], int mID, int mPoint){
    int uid=update_user(mUser,mPoint);
    int mid=midx++;
    msgmap[mID]=mid;
    msgs[mid].id=mID;
    msgs[mid].isvalid=true;
    msgs[mid].par=-1;
    msgs[mid].point=mPoint;
    msgs[mid].root=mPoint;
    msgs[mid].uid=uid;
    msgset.insert(mid);
    msg_gr[mid].clear();
    return users[uid].point;
}
int commentTo(char mUser[], int mID, int mTargetID, int mPoint){
    int uid=update_user(mUser,mPoint);
    int mid=midx++;
    int par=msgmap[mTargetID];
    int rootid=findpar(par);
    msgmap[mID]=mid;
    msgs[mid].id=mID;
    msgs[mid].isvalid=true;
    msgs[mid].par=par;
    msgs[mid].point=mPoint;
    msgs[mid].root=mPoint;
    msgs[mid].uid=uid;
    msgset.erase(rootid);
    msgs[rootid].point+=mPoint;
    msgset.insert(rootid);
    msg_gr[par].push_back(mid);
    msg_gr[mid].clear();
    return msgs[rootid].point;
}
void rec_erase(int cur, int root){
    for(auto it: msg_gr[cur]){
        if(msgs[it].isvalid){
            int uid=msgs[it].uid;
            userset.erase(uid);
            msgs[it].isvalid=false;
            users[uid].point-=msgs[it].root;
            userset.insert(uid);
            msgs[root].point-=msgs[it].root;
            rec_erase(it,root);
        }
    }
}
int erase(int mID){
    int mid=msgmap[mID];
    int uid=msgs[mid].uid;
    int rootid=findpar(mid);
    msgset.erase(rootid);
    rec_erase(mid,rootid);
    msgs[rootid].point-=msgs[mid].root;
    msgs[mid].isvalid=false;
    msgset.insert(rootid);
    userset.erase(uid);
    users[uid].point-=msgs[mid].root;
    userset.insert(uid);
    if(msgs[mid].par==-1) return users[uid].point;
    else
        return msgs[rootid].point;
}
void getBestMessages(int mBestMessageList[]){
    int i = 0;
    for (auto it : msgset) {
        mBestMessageList[i] = msgs[it].id;
        i++;
        if (i >= 5) break;
    }
   
    return;
}
   
void getBestUsers(char mBestUserList[][MAXL + 1]){
    int i = 0;
    for (auto it : userset) {
        int j = 0;
        for (; j < users[it].name.size(); j++) {
            mBestUserList[i][j] = users[it].name[j];
        }
        mBestUserList[i][j] = '\0';
        i++;
        if (i >= 5) break;
    }
   
    return;
}
/////
25 100
20
100
200 aaa 1 10 10
200 bbb 2 5 5
300 ccc 3 1 5 15
300 ddd 4 1 3 18
300 eee 5 3 4 22
600 aaa bbb ccc eee ddd
200 ccc 6 20 25
200 bbb 7 13 18
200 aaa 8 20 30
500 1 6 8 7 2
200 fff 9 1 1
300 ddd 10 6 10 30
400 3 13
600 aaa ccc bbb ddd fff
400 6 0
300 ccc 20 2 35 40
300 fff 30 9 14 15
500 2 8 9 1 7
600 ccc aaa bbb fff ddd
27
100
200 t 424 9 9
200 mpky 7 7 7
300 l 492 7 1 8
300 p 860451 424 6 15
300 hv 2158753 860451 2 17
300 t 8225355 492 1 9
300 hv 9 860451 2 19
200 kzwgyt 56 9 9
200 mpky 90388 6 13
400 492 7
600 mpky kzwgyt t p hv
200 geur 905 1 1
200 geur 558 1 2
500 424 56 7 90388 558
300 mpky 532037 90388 6 12
300 geur 4380 532037 8 20
300 kzwgyt 580534984 905 5 6
200 l 12838 4 4
300 p 95050 90388 6 26
200 kzwgyt 81 1 15
300 zfu 2 424 8 27
400 12838 0
200 mpky 110748 1 20
200 xp 88696 3 3
500 424 90388 56 7 905
600 mpky kzwgyt p geur t
30
100
200 aacavqgdp 7 5 5
300 lrqnbomnee 142 7 1 6
200 wcupanr 43067 7 7
400 43067 0
200 spov 8164 7 7
200 aacavqgdp 908 4 9
300 dcwu 2776 8164 6 13
300 rremgki 133402 908 1 5
300 f 86721532 8164 9 22
300 eahtiqa 966012 2776 4 26
300 f 99108 7 6 12
200 wcupanr 515 4 4
200 rremgki 17057588 4 5
200 dcwu 326332 5 11
200 cxoba 71 1 1
600 f dcwu aacavqgdp spov rremgki
400 71 0
300 ywb 8078 326332 7 12
500 8164 7 326332 908 515
200 cxoba 2 7 7
300 lrqnbomnee 53670 8164 2 28
300 f 9 8078 4 16
200 eahtiqa 4 5 9
200 eahtiqa 1 4 13
300 lrqnbomnee 5165 2 9 16
400 966012 24
300 wcupanr 70 99108 6 18
500 8164 7 2 326332 4
600 f lrqnbomnee dcwu wcupanr aacavqgdp
Editor is loading...
Leave a Comment