正文
增加 6 行删除 6 行
44 行未改动45464748495051525344 行未改动989910010110210310410510610710849 行未改动1581591601611621631641651664 行未改动1711721731741751761771781791801814 行未改动44 行未改动auto rs = [](int x) {return x << 1|1;};void push_up(int p) {tr[p] = tr[ls(p)] + tr[rs(p)];}void addtag (int p, int pl, int pr, i64 d) {tag[p] = tag[p] + d;tr[p] = (pr - pl + 1) * d + tr[p];}void push_down(int p, int pl, int pr) {if (tag[p]) {int mid = (pl + pr) >> 1;44 行未改动cin >> op >> x;if (op == 1) {cin >> c;auto it = S[c].upper_bound(dfn[x]);if (it != S[c].begin())if (calEnd(p[*prev(it)]) >= calEnd(x)) continue;while (it != S[c].end() && *it <= calEnd(x))update(*it, calEnd(p[*it]), -1, 1, 1, n), S[c].erase(it ++);S[c].insert(dfn[x]);update(dfn[x], calEnd(x), 1, 1, 1, n);}49 行未改动}dfs (1, 0);auto calEnd = [&](int u) {return dfn[u] + siz[u] - 1;};auto getAns = [&](int u) {return siz[u] * Tr1.query(dfn[u]) +Tr2.query(calEnd(u)) - Tr2.query(dfn[u]);};auto change = [&](int u, i64 d) {Tr1.update(dfn[u], d);4 行未改动cin >> op >> x;if (op == 1) {cin >> c;auto it = S[c].upper_bound(dfn[x]);if (it != S[c].begin())if (calEnd(p[*prev(it)]) >= calEnd(x)) continue;while (it != S[c].end() && *it <= calEnd(x))change(p[*it], -1), S[c].erase(it ++);S[c].insert(dfn[x]), change(x, 1);}else cout << getAns(x) << '\n';4 行未改动44 行未改动45464748495051525344 行未改动989910010110210310410510610710849 行未改动1581591601611621631641651664 行未改动1711721731741751761771781791801814 行未改动44 行未改动auto rs = [](int x) {return x << 1|1;};void push_up(int p) {tr[p] = tr[ls(p)] + tr[rs(p)];}void addtag (int p, int pl, int pr, i64 d) {tag[p] = tag[p] + d;tr[p] = (pr - pl + 1) * d + tr[p];}void push_down(int p, int pl, int pr) {if (tag[p]) {int mid = (pl + pr) >> 1;44 行未改动cin >> op >> x;if (op == 1) {cin >> c;auto it = S[c].upper_bound(dfn[x]);if (it != S[c].begin())if (calEnd(p[*prev(it)]) >= calEnd(x)) continue;while (it != S[c].end() && *it <= calEnd(x))update(*it, calEnd(p[*it]), -1, 1, 1, n), S[c].erase(it ++);S[c].insert(dfn[x]);update(dfn[x], calEnd(x), 1, 1, 1, n);}49 行未改动}dfs (1, 0);auto calEnd = [&](int u) {return dfn[u] + siz[u] - 1;};auto getAns = [&](int u) {return siz[u] * Tr1.query(dfn[u]) +Tr2.query(calEnd(u)) - Tr2.query(dfn[u]);};auto change = [&](int u, i64 d) {Tr1.update(dfn[u], d);4 行未改动cin >> op >> x;if (op == 1) {cin >> c;auto it = S[c].upper_bound(dfn[x]);if (it != S[c].begin())if (calEnd(p[*prev(it)]) >= calEnd(x)) continue;while (it != S[c].end() && *it <= calEnd(x))change(p[*it], -1), S[c].erase(it ++);S[c].insert(dfn[x]), change(x, 1);}else cout << getAns(x) << '\n';4 行未改动