平面上 n 個點,m 次操作:
u=0, v:轟炸 x=v 縱線上所有點,輸出被炸數量u=1, v:轟炸 y=v 橫線上所有點,輸出被炸數量被炸點從集合中移除。n,m ≤ 10000。
map cntX, cntY :統計每條縱/橫線點數multiset setX :按 x 後 y 排序multiset setY :按 y 後 x 排序setX 中 lower_bound 找到範圍,逐個刪除並同步刪除 setY 中對應點,更新計數
struct X { int x,y; bool operator<(X o) const { return x!=o.x? x sx; multiset sy;
map cx, cy;
void bombX(int v) {
if (!cx.count(v)) { puts("0"); return; }
printf("%d\n", cx[v]);
cx.erase(v);
auto it = sx.lower_bound({v, -INF});
while (it != sx.end() && it->x == v) {
int y = it->y;
sy.erase(sy.find({v, y}));
if (--cy[y] == 0) cy.erase(y);
auto tmp = it++;
sx.erase(tmp);
}
}
multiset 操作 O(log n)O((n+m) log n)