正文
增加 3 行删除 3 行
48 行未改动4950515253545556575 行未改动636465666768697071169 行未改动全部展开24124224324424524624724824942 行未改动48 行未改动cin >> a[i].v;a[i].id = i;}sort(a + 1, a + n + 1, cmp);for (int i = 1; i <= n; i++)b[i] = a[i].v;int l = 0, cnt = 0; \\l为左边选的数的个数(不含值相等的数),cnt为左边选的值相等的数的个数for (int i = 1; i <= n; i++) {int rpos = upper_bound(b + 1, b + n + 1, a[i].v) - b; \\右边选的数的个数5 行未改动ans += a[i].v + k * (n - rpos + 1);tot++;cnt++; \\这里先把l++变为cnt++v.push_back(a[i].id);} elseans -= l * k; \\把之前在这个数上加的 k 删掉}cout << ans << ' ' << tot << '\n';for (int i = 0; i < v.size(); i++)169 行未改动全部展开}if (x != 1)p[x] = fact * cnt[x] % P * (m - cnt[x]) % P * 2 % P; \\x到其父节点的边的期望(这里我没有乘ifa,在输出时再乘的)b[x] = (b[x] + p[x]) % P;}signed main() {ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);42 行未改动48 行未改动4950515253545556575 行未改动636465666768697071169 行未改动全部展开24124224324424524624724824942 行未改动48 行未改动cin >> a[i].v;a[i].id = i;}sort(a + 1, a + n + 1, cmp);for (int i = 1; i <= n; i++)b[i] = a[i].v;int l = 0, cnt = 0; \\l为左边选的数的个数(不含值相等的数),cnt为左边选的值相等的数的个数for (int i = 1; i <= n; i++) {int rpos = upper_bound(b + 1, b + n + 1, a[i].v) - b; \\右边选的数的个数5 行未改动ans += a[i].v + k * (n - rpos + 1);tot++;cnt++; \\这里先把l++变为cnt++v.push_back(a[i].id);} elseans -= l * k; \\把之前在这个数上加的 k 删掉}cout << ans << ' ' << tot << '\n';for (int i = 0; i < v.size(); i++)169 行未改动全部展开}if (x != 1)p[x] = fact * cnt[x] % P * (m - cnt[x]) % P * 2 % P; \\x到其父节点的边的期望(这里我没有乘ifa,在输出时再乘的)b[x] = (b[x] + p[x]) % P;}signed main() {ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);42 行未改动