版本比较
Solution Of P5852 [USACO19DEC] Bessie's Snow Cow P
正文
增加 6 行删除 6 行
44 行未改动4546474849495051525344 行未改动989910010110210210310410410510610710849 行未改动1581591601611621621631641651664 行未改动1711721731741751751761771771781791801814 行未改动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]; 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 (it != S[c].begin()) if (calEnd(p[*prev(it)]) >= calEnd(x)) continue; while (it != S[c].end() && *it <= calEnd(x)) 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]) + 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 (it != S[c].begin()) if (calEnd(p[*prev(it)]) >= calEnd(x)) continue; while (it != S[c].end() && *it <= calEnd(x)) 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 行未改动