Untitled
unknown
plain_text
a year ago
978 B
5
Indexable
#include <queue>
#include <unordered_map>
using namespace std;
struct cmp{
bool operator()(pair<int, int> a, pair<int, int> b) {
if(a.second - a.first == b.second - b.first) {
return a.first > b.first;
}
return a.second - a.first < b.second - b.first;
}
};
int n;
priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> pq;
void init(int N){
n = N;
while(!pq.empty()) {
pq.pop();
}
pq.push(make_pair(0, n-1));
}
int build(int mLength){
int res = -1;
auto land = pq.top();
int left = land.first;
int right = land.second;
if(right - left + 1 >= mLength) {
pq.pop();
int temp = right - left - mLength;
if(temp < 2) {
res = left;
}
else {
res = left + temp/2;
}
if(res > left) {
pq.push(make_pair(left, res - 1));
}
if(res + mLength - 1 < right) {
pq.push(make_pair(res + mLength, right));
}
return res;
}
return res;
}
int demolish(int mAddr){
return -1;
}
Editor is loading...
Leave a Comment