qiaobaaa / response3

0 stars 0 forks source link

werwerwe #1

Open qiaobaaa opened 1 year ago

qiaobaaa commented 1 year ago

using namespace std; struct block { int sc; int len; int ec; int time; int block[10000]; }B[1000]; int r, c; int idx; void init(int R, int C) { r = R; c = C; idx = 0; }

int dropBlocks(int mTimestamp, int mCol, int mLen) { int total =0; for (int i = idx - 1; i >= 0; i--) { if (mTimestamp - B[i].time < r) total += B[i].len; } B[idx].sc = mCol; B[idx].ec = mCol + mLen; B[idx].len = mLen; B[idx].time = mTimestamp; for (int i = mCol; i < mCol + mLen; i++) B[idx].block[i] = 1; total += mLen; idx++; return total; }

int removeBlocks(int mTimestamp) { int total = 0; int visit[10000] = { 0 }; for (int i = 0; i < idx; i++) { if (mTimestamp - B[i].time < r) { for (int j = B[i].sc; j < B[i].ec; j++) { if (visit[j] == 0 && B[i].block[j] == 1) { visit[j] = 1; B[i].block[j] = 0; B[i].len--; } } total += B[i].len; } } return total; }