Untitled
unknown
plain_text
a year ago
3.2 kB
4
Indexable
Never
#include<iostream> #include<unordered_map> #include<string> #include<vector> #include<set> using namespace std; #define MAXM (10) #define MAXL (11) struct Node{ int st,end; vector<string> mem; bool alive; }pool[10000]; unordered_map<string, int> meet; unordered_map<string, int> member; class cmp{ public: bool operator ()(const int n1, const int n2){ if(pool[n1].end!=pool[n2].end)return pool[n1].end<pool[n2].end; return n1<n2; } }; set<int, cmp> myset[10000]; string a; int cnt,cnt1; bool checkoverlap(string a, int st, int end){ bool flag=false; for(int k:myset[member[a]]){ if(pool[k].end<st || pool[k].st>end){ continue; } flag=true; } return flag; } void init() { meet.clear(); member.clear(); for(int i=0;i<10000;i++){ myset[i].clear(); } cnt=0; cnt1=0; } int addMeeting(char mMeeting[MAXL], int M, char mMemberList[MAXM][MAXL], int mStartTime, int mEndTime) { int ans=0; a = mMeeting; pool[cnt].st=mStartTime; pool[cnt].end=mEndTime; pool[cnt].alive=true; meet[a]=cnt; for(int i=0;i<M;i++){ string b=mMemberList[i]; auto it = member.find(b); if(it == member.end()){ member[b]=cnt1; myset[cnt1].insert(cnt); pool[cnt].mem.push_back(b); cnt1++; }else{ if(checkoverlap(b,mStartTime,mEndTime))continue; myset[it->second].insert(cnt); pool[cnt].mem.push_back(b); } } ans=pool[cnt].mem.size(); cnt++; return ans; } int cancelMeeting(char mMeeting[MAXL]) { a=mMeeting; auto it=meet.find(a); if(it == meet.end() || pool[it->second].alive==false)return 0; pool[it->second].alive=false; for(int i=0;i<pool[it->second].mem.size();i++){ string b= pool[it->second].mem[i]; myset[member[b]].erase(it->second); } meet.erase(a); return 1; } int changeMeetingMember(char mMeeting[MAXL], char mMember[MAXL]) { a=mMeeting; string b= mMember; auto it =meet.find(a); if(it ==meet.end() || pool[it->second].alive==false){ return -1; } for(int i=0;i<pool[it->second].mem.size();i++){ if(pool[it->second].mem[i]==b){ pool[it->second].mem.erase(pool[it->second].mem.begin()+i); myset[member[b]].erase(it->second); return 0; } } auto at = member.find(b); if(at==member.end()){ myset[cnt1].insert(it->second); member[b]=cnt1++; }else{ if(checkoverlap(b,pool[it->second].st,pool[it->second].end))return 2; myset[at->second].insert(it->second); } pool[it->second].mem.push_back(b); return 1; } int changeMeeting(char mMeeting[MAXL], int mStartTime, int mEndTime) { a=mMeeting; auto it =meet.find(a); if(it == meet.end() || pool[it->second].alive==false)return 0; pool[it->second].st=mStartTime; pool[it->second].end=mEndTime; for(int i=0;i<pool[it->second].mem.size();i++){ string b=pool[it->second].mem[i]; if(checkoverlap(b,mStartTime,mEndTime)){ pool[it->second].mem.erase(pool[it->second].mem.begin()+i); myset[member[b]].erase(it->second); } } if(pool[it->second].mem.size()==0)return 0; return pool[it->second].mem.size(); } void checkNextMeeting(char mMember[MAXL], int mTime, char mResult[MAXL]) { }