Open qiaobaaa opened 1 year ago
using namespace std;
struct MyStruct { int start; int end; }pool[9000];
//start set<pair<int, pair<int, int>>>sset1;
int numcnt; unordered_map<int, int>umap;
void init() { sset1.clear(); umap.clear(); numcnt = 0; return; }
int add(int mId, int mStart, int mEnd) { if (umap.count(mId) == 1) { int index = umap[mId]; sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index)));
umap[mId] = numcnt; pool[numcnt].start = mStart; pool[numcnt].end = mEnd; sset1.emplace(make_pair(mStart, make_pair(mEnd, numcnt))); numcnt++; return umap.size(); } umap[mId] = numcnt; pool[numcnt].start = mStart; pool[numcnt].end = mEnd; sset1.emplace(make_pair(mStart, make_pair(mEnd, numcnt))); numcnt++; return umap.size();
}
int remove(int mId) { if (umap.count(mId)) { int index = umap[mId]; sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index))); umap.erase(mId); return umap.size(); } return umap.size(); }
struct cmd { bool operator()(const pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) const { return a.second.first > b.second.first; } };
int announce(int mDuration, int M) {
int e; priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, cmd> pq; for (auto i : sset1) { e = i.first + mDuration - 1; pq.push(i); while (!pq.empty()) { if (pq.top().second.first < e) { pq.pop(); } else { break; } } if (pq.size() >= M) { return i.first; } } return -1;
include
include
include
using namespace std;
struct MyStruct { int start; int end; }pool[9000];
//start set<pair<int, pair<int, int>>>sset1;
int numcnt; unordered_map<int, int>umap;
void init() { sset1.clear(); umap.clear(); numcnt = 0; return; }
int add(int mId, int mStart, int mEnd) { if (umap.count(mId) == 1) { int index = umap[mId]; sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index)));
}
int remove(int mId) { if (umap.count(mId)) { int index = umap[mId]; sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index))); umap.erase(mId); return umap.size(); } return umap.size(); }
struct cmd { bool operator()(const pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) const { return a.second.first > b.second.first; } };
int announce(int mDuration, int M) {
}