版本比较
题解:P13342 [EGOI 2025] Wind Turbines / 风力涡轮机
正文
增加 8 行删除 8 行
45 行未改动46474849505152535418 行未改动737475767778798081828384858687884 行未改动939495969798991001011021031042 行未改动10710810911011111211311411511611711811912012112212312412512612712845 行未改动int query (int x) {int ret = 0;for ( ; x; x -= x & -x) ret += bits[x];return ret;}vector<int> e[_];int v[_], sz[_], son[_];18 行未改动for (auto [x, y, z] : g) {x = find(x), y = find(y);if (x != y) {++ tn;anc[x] = anc[y] = tn;sum += z, v[tn] = z;e[tn].push_back(x), e[tn].push_back(y);}}} ;auto pre_dfs = [&](auto &self, int x) -> void {dfn[x] = ++ dfc;id[dfc] = x;sz[x] = 1;for (int y : e[x]) {self(self, y);4 行未改动} ;auto ins = [&](int x, int lca) -> void {auto it = s.lower_bound(x);if (it != s.end()) cv[*it].push_back({x, lca});if (it != s.begin()) cv[x].push_back({*prev(it), lca});} ;auto dsu = [&](auto &self, int x, int ty) -> void {for (int y : e[x])if (y ^ son[x]) self(self, y, 0);if (son[x]) self(self, son[x], 1);for (int y : e[x]) {if (y == son[x]) continue ;2 行未改动}if (!ty)rep(i, dfn[x], ed[x]) s.erase(id[i]);else if (x <= n) s.insert(x);} ;kruskal();pre_dfs(pre_dfs, tn);dsu(dsu, tn, 0);rep(i, 1, q) {int l = read() + 1, r = read() + 1;qv[r].push_back({l, i});}rep(r, 1, n) {for (auto [l, c] : cv[r])if (l > col[c]) { add(col[c], -v[c]); col[c] = l; add(col[c], v[c]); }for (auto [l, id] : qv[r])ans[id] = query(r) - query(l - 1);}rep(i, 1, q) printf("%lld\n", sum - ans[i]);return 0;}```45 行未改动46474849505152535418 行未改动737475767778798081828384858687884 行未改动939495969798991001011021031042 行未改动10710810911011111211311411511611711811912012112212312412512612712845 行未改动int query (int x) {int ret = 0;for ( ; x; x -= x & -x) ret += bits[x];return ret;}vector<int> e[_];int v[_], sz[_], son[_];18 行未改动for (auto [x, y, z] : g) {x = find(x), y = find(y);if (x != y) {++ tn;anc[x] = anc[y] = tn;sum += z, v[tn] = z;e[tn].push_back(x), e[tn].push_back(y);}}} ;auto pre_dfs = [&](auto &self, int x) -> void {dfn[x] = ++ dfc;id[dfc] = x;sz[x] = 1;for (int y : e[x]) {self(self, y);4 行未改动} ;auto ins = [&](int x, int lca) -> void {auto it = s.lower_bound(x);if (it != s.end()) cv[*it].push_back({x, lca});if (it != s.begin()) cv[x].push_back({*prev(it), lca});} ;auto dsu = [&](auto &self, int x, int ty) -> void {for (int y : e[x])if (y ^ son[x]) self(self, y, 0);if (son[x]) self(self, son[x], 1);for (int y : e[x]) {if (y == son[x]) continue ;2 行未改动}if (!ty)rep(i, dfn[x], ed[x]) s.erase(id[i]);else if (x <= n) s.insert(x);} ;kruskal();pre_dfs(pre_dfs, tn);dsu(dsu, tn, 0);rep(i, 1, q) {int l = read() + 1, r = read() + 1;qv[r].push_back({l, i});}rep(r, 1, n) {for (auto [l, c] : cv[r])if (l > col[c]) { add(col[c], -v[c]); col[c] = l; add(col[c], v[c]); }for (auto [l, id] : qv[r])ans[id] = query(r) - query(l - 1);}rep(i, 1, q) printf("%lld\n", sum - ans[i]);return 0;}```