Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
0
Indexable
Never
#include<set>
 
using namespace std;
  
set<int> mMap[2005];
int pool[100000];
int mxHeight;
  
void init(int N) {
    mxHeight = 0;
    for (int i = 0; i < 2005; i++) {
        mMap[i].clear();
    }
    for (int i = 0; i < N + 1; i++) {
        pool[i] = 0;
    }
    return;
}
  
int getArea() {
    int ans = 0;
    for (int i = 0; i <= mxHeight;i++) {
        if (!mMap[i].empty()) {
            ans += (*mMap[i].rbegin() - *mMap[i].begin() + 1);
        }
    }
    return ans;
}
  
int stock(int mLoc, int mBox) {
    for (int i = pool[mLoc]; i < pool[mLoc] + mBox; i++) {
        mMap[i].insert(mLoc);
    }
    pool[mLoc] += mBox;
    if (mxHeight < pool[mLoc]) {
        mxHeight = pool[mLoc];
    }
    return getArea();
}
  
int ship(int mLoc, int mBox) {
    for (int i = pool[mLoc]; i > pool[mLoc] - mBox; i--) {
        mMap[i - 1].erase(mLoc);
    }
    pool[mLoc] -= mBox;
    return getArea();
}
  
int getHeight(int mLoc) {
    return pool[mLoc];
}