正文
增加 32 行删除 32 行
145 行未改动全部展开14614714814915015115215315486 行未改动2412422432442452462472482492502512522532542552562572582592602612627 行未改动27027127227327427527627727827928028128228328417 行未改动30230330430530630730830931031131231331431531631731831932032132232322 行未改动34634734834935035135235335435535635735835936036136236336436536636736836937037137237337437530 行未改动4064074084094104114124134144154164174184194204214224234244254264274284294304314329 行未改动44244344444544644744844945045145245345445545645745845946046146246315 行未改动47948048148248348448548648721 行未改动50951051151251351451551651751851952052152252352452512 行未改动53853954054154254354454554654754854955055155255355455555655755816 行未改动57557657757857958058158258358458573 行未改动145 行未改动全部展开return 0;}```# 树套树解[狗狗](https://www.luogu.com.cn/problem/P1533)(Ds代码,会[TLE和MLE](https://www.luogu.com.cn/record/243558478))```cpp#include <iostream>#include <cstdio>86 行未改动struct SegNode {Node* root;SegNode() : root(nullptr) {}} tree[MAXN * 4];int n;vector<int> arr;void build(int p, int l, int r) {for (int i = l; i <= r; i++) {insert(tree[p].root, arr[i]);}if (l == r) return;int mid = (l + r) / 2;build(p * 2, l, mid);build(p * 2 + 1, mid + 1, r);}// 查询区间内小于等于 x 的数的个数int queryRank(int p, int l, int r, int ql, int qr, int x) {if (ql <= l && r <= qr) {// 在平衡树中查询小于等于 x 的数的个数7 行未改动if (ql <= mid) res += queryRank(p * 2, l, mid, ql, qr, x);if (qr > mid) res += queryRank(p * 2 + 1, mid + 1, r, ql, qr, x);return res;}public:SegmentTree(const vector<int>& a) : arr(a) {n = a.size() - 1;build(1, 1, n);}// 查询区间第 k 小值int queryKth(int ql, int qr, int k) {// 二分答案int left = 0, right = 1e9, ans = 0;17 行未改动vector<int> a(n + 1);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}SegmentTree segTree(a);while (m--) {int i, j, k;scanf("%d%d%d", &i, &j, &k);printf("%d\n", segTree.queryKth(i, j, k));}return 0;}```# Splayds,CE```cpp#include<bits/stdc++.h>22 行未改动void rotate(int i, bool d) {// d=0: 左旋, d=1: 右旋int f = fth[i], gf = fth[f];pushdown(i); pushdown(f);son[f][!d] = son[i][d];if (son[i][d]) fth[son[i][d]] = f;son[i][d] = f;fth[f] = i;fth[i] = gf;if (gf) {if (son[gf][0] == f) son[gf][0] = i;else son[gf][1] = i;}update(f);update(i);}void splay(int i, int goal) {while (fth[i] != goal) {int f = fth[i], gf = fth[f];pushdown(gf); pushdown(f); pushdown(i);if (gf == goal) {rotate(i, son[f][0] == i);} else {bool d1 = (son[f][0] == i);30 行未改动int build(int l, int r, int fa) {if (l > r) return 0;int mid = (l + r) >> 1;int i = ++cnt;fth[i] = fa;val[i] = cp[mid];siz[i] = 1;laz[i] = 0;son[i][0] = build(l, mid - 1, i);son[i][1] = build(mid + 1, r, i);update(i);return i;}void reverse(int l, int r) {int L = findkth(l - 1);int R = findkth(r + 1);splay(L, 0);splay(R, L);int pos = son[R][0];laz[pos] ^= 1;}9 行未改动int main() {int n, m;cin >> n >> m;// 添加哨兵节点cp[1] = 0; // 左哨兵for (int i = 1; i <= n; i++) cp[i + 1] = i;cp[n + 2] = n + 1; // 右哨兵rot = build(1, n + 2, 0);while (m--) {int l, r;cin >> l >> r;reverse(l + 1, r + 1); // 因为有两个哨兵}dfs(rot);return 0;}```15 行未改动int n,m;int cl[maxn];bool flg=1;void dfs(int u,int c,int p) {cl[u]=c;for(int i=hed[u];i;i=nxt[i]) {if(dii[i]==p) continue;if(!flg) return;int v=too[i];21 行未改动for(int u,v,i=1; i<=m; i++) {cin>>u>>v;add(u,v,i);add(v,u,i);}for(int i=1; i<=m; i++) {if(ck(i)){ans[++ant]=i;}}cout<<ant<<'\n';for(int i=1;i<=ant;i++) cout<<ans[i]<<' ';}```# 2025 CSP-S T1```#include<iostream>#include<algorithm>using namespace std;12 行未改动int main(){ios::sync_with_stdio(false);cin.tie(0);int t;cin >> t;while(t--){int n, _n, size[3] = {0}, ans = 0;cin >> n;_n = n / 2;for(int i = 0; i < n; i++){cin >> peo[i].a >> peo[i].b >> peo[i].c;// 更简洁的写法确定最优和次优if(peo[i].a >= peo[i].b && peo[i].a >= peo[i].c){peo[i].fri = peo[i].a;16 行未改动peo[i].secid = (peo[i].a >= peo[i].b) ? 0 : 1;}peo[i].dis = peo[i].fri - peo[i].sec;}sort(peo, peo + n, cmp);for(int i = 0; i < n; i++){if(size[peo[i].friid] < _n){73 行未改动145 行未改动全部展开14614714814915015115215315486 行未改动2412422432442452462472482492502512522532542552562572582592602612627 行未改动27027127227327427527627727827928028128228328417 行未改动30230330430530630730830931031131231331431531631731831932032132232322 行未改动34634734834935035135235335435535635735835936036136236336436536636736836937037137237337437530 行未改动4064074084094104114124134144154164174184194204214224234244254264274284294304314329 行未改动44244344444544644744844945045145245345445545645745845946046146246315 行未改动47948048148248348448548648721 行未改动50951051151251351451551651751851952052152252352452512 行未改动53853954054154254354454554654754854955055155255355455555655755816 行未改动57557657757857958058158258358458573 行未改动145 行未改动全部展开return 0;}```# 树套树解[狗狗](https://www.luogu.com.cn/problem/P1533)(Ds代码,会[TLE和MLE](https://www.luogu.com.cn/record/243558478))```cpp#include <iostream>#include <cstdio>86 行未改动struct SegNode {Node* root;SegNode() : root(nullptr) {}} tree[MAXN * 4];int n;vector<int> arr;void build(int p, int l, int r) {for (int i = l; i <= r; i++) {insert(tree[p].root, arr[i]);}if (l == r) return;int mid = (l + r) / 2;build(p * 2, l, mid);build(p * 2 + 1, mid + 1, r);}// 查询区间内小于等于 x 的数的个数int queryRank(int p, int l, int r, int ql, int qr, int x) {if (ql <= l && r <= qr) {// 在平衡树中查询小于等于 x 的数的个数7 行未改动if (ql <= mid) res += queryRank(p * 2, l, mid, ql, qr, x);if (qr > mid) res += queryRank(p * 2 + 1, mid + 1, r, ql, qr, x);return res;}public:SegmentTree(const vector<int>& a) : arr(a) {n = a.size() - 1;build(1, 1, n);}// 查询区间第 k 小值int queryKth(int ql, int qr, int k) {// 二分答案int left = 0, right = 1e9, ans = 0;17 行未改动vector<int> a(n + 1);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}SegmentTree segTree(a);while (m--) {int i, j, k;scanf("%d%d%d", &i, &j, &k);printf("%d\n", segTree.queryKth(i, j, k));}return 0;}```# Splayds,CE```cpp#include<bits/stdc++.h>22 行未改动void rotate(int i, bool d) {// d=0: 左旋, d=1: 右旋int f = fth[i], gf = fth[f];pushdown(i); pushdown(f);son[f][!d] = son[i][d];if (son[i][d]) fth[son[i][d]] = f;son[i][d] = f;fth[f] = i;fth[i] = gf;if (gf) {if (son[gf][0] == f) son[gf][0] = i;else son[gf][1] = i;}update(f);update(i);}void splay(int i, int goal) {while (fth[i] != goal) {int f = fth[i], gf = fth[f];pushdown(gf); pushdown(f); pushdown(i);if (gf == goal) {rotate(i, son[f][0] == i);} else {bool d1 = (son[f][0] == i);30 行未改动int build(int l, int r, int fa) {if (l > r) return 0;int mid = (l + r) >> 1;int i = ++cnt;fth[i] = fa;val[i] = cp[mid];siz[i] = 1;laz[i] = 0;son[i][0] = build(l, mid - 1, i);son[i][1] = build(mid + 1, r, i);update(i);return i;}void reverse(int l, int r) {int L = findkth(l - 1);int R = findkth(r + 1);splay(L, 0);splay(R, L);int pos = son[R][0];laz[pos] ^= 1;}9 行未改动int main() {int n, m;cin >> n >> m;// 添加哨兵节点cp[1] = 0; // 左哨兵for (int i = 1; i <= n; i++) cp[i + 1] = i;cp[n + 2] = n + 1; // 右哨兵rot = build(1, n + 2, 0);while (m--) {int l, r;cin >> l >> r;reverse(l + 1, r + 1); // 因为有两个哨兵}dfs(rot);return 0;}```15 行未改动int n,m;int cl[maxn];bool flg=1;void dfs(int u,int c,int p) {cl[u]=c;for(int i=hed[u];i;i=nxt[i]) {if(dii[i]==p) continue;if(!flg) return;int v=too[i];21 行未改动for(int u,v,i=1; i<=m; i++) {cin>>u>>v;add(u,v,i);add(v,u,i);}for(int i=1; i<=m; i++) {if(ck(i)){ans[++ant]=i;}}cout<<ant<<'\n';for(int i=1;i<=ant;i++) cout<<ans[i]<<' ';}```# 2025 CSP-S T1```#include<iostream>#include<algorithm>using namespace std;12 行未改动int main(){ios::sync_with_stdio(false);cin.tie(0);int t;cin >> t;while(t--){int n, _n, size[3] = {0}, ans = 0;cin >> n;_n = n / 2;for(int i = 0; i < n; i++){cin >> peo[i].a >> peo[i].b >> peo[i].c;// 更简洁的写法确定最优和次优if(peo[i].a >= peo[i].b && peo[i].a >= peo[i].c){peo[i].fri = peo[i].a;16 行未改动peo[i].secid = (peo[i].a >= peo[i].b) ? 0 : 1;}peo[i].dis = peo[i].fri - peo[i].sec;}sort(peo, peo + n, cmp);for(int i = 0; i < n; i++){if(size[peo[i].friid] < _n){73 行未改动