1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #define high(x) (31 - __builtin_clz(x))
struct Node { LL nd, sum; Node operator +(Node t) const { LL ret = std::max(nd, nd - sum + t.nd); return {ret, ret + t.sum + sum - nd - t.nd}; } }; struct Monster { int st, ed, x, y, z; Node add; bool operator <(Monster t) const { return std::min(-add.nd, -add.nd + add.sum - t.add.nd) > std::min(-t.add.nd, -t.add.nd + t.add.sum - add.nd); } } mon[N]; struct Query { int x, y, z, at; Node res; } q[N]; int m, n, Q, havx[S], havy[S], havz[S]; Node ans[1 << B | 10];
void solve(int l, int r) { int len = r - l + 1; for (int i = 1; i < (1 << len); ++ i) ans[i] = ans[i ^ (1 << high(i))] + mon[high(i) + l].add; for (int i = 0; i < S; ++ i) havx[i] = havy[i] = havz[i] = 0; for (int i = l, id; i <= r; ++ i) { havx[mon[i].x] |= 1 << (id = i - l); havy[mon[i].y] |= 1 << id, havz[mon[i].z] |= 1 << id; } for (int i = 1; i < S; ++ i) havx[i] |= havx[i - 1], havy[i] |= havy[i - 1], havz[i] |= havz[i - 1]; std::vector<int> id1(r - l + 1); for (int i = l; i <= r; ++ i) id1[i - l] = i; std::vector<int> id2(id1); std::sort(id1.begin(), id1.end(), [&](int x, int y) { return mon[x].st < mon[y].st; }); std::sort(id2.begin(), id2.end(), [&](int x, int y) { return mon[x].ed < mon[y].ed; }); auto iter1 = id1.begin(), iter2 = id2.begin(); for (int i = 1, hav = 0; i <= Q; ++ i) { while (iter1 != id1.end() && mon[*iter1].st <= q[i].at) hav ^= 1 << (*(iter1 ++) - l); while (iter2 != id2.end() && mon[*iter2].ed <= q[i].at) hav ^= 1 << (*(iter2 ++) - l); q[i].res = q[i].res + ans[hav & havx[q[i].x] & havy[q[i].y] & havz[q[i].z]]; } }
int main() { std::cin >> m; char op[3]; for (int i = 1, id, t = 0; i <= m; ++ i) { scanf("%s", op); if (*op == '+') ++ n, scanf("%d %d %d %lld %lld", &mon[n].x, &mon[n].y, &mon[n].z, &mon[n].add.nd, &mon[n].add.sum), mon[n].st = ++ t; else if (*op == '-') scanf("%d", &id), mon[id].ed = ++ t; else if (*op == '?') ++ Q, scanf("%d %d %d", &q[Q].x, &q[Q].y, &q[Q].z), q[Q].at = t; else assert(false); } for (int i = 1; i <= n; ++ i) ; for (int i = 1; i <= n; ++ i) if (!mon[i].ed) mon[i].ed = m + 1; std::sort(mon + 1, mon + n + 1); for (int l = 1, r; l <= n; l = r + 1) solve(l, r = std::min(n, l + B - 1)); for (int i = 1; i <= Q; ++ i) printf("%lld\n", q[i].res.nd); return 0; }
|