版本比较
代码源考试总结(全集)
正文
增加 1246 行删除 0 行
924 行未改动全部展开92592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174924 行未改动全部展开
一句话评价:我是zrr🐷。
对于时间分配还是不行,实则没有打暴力的欲望。代码调试能力有待加强🚀!思路分析不过严谨😡!
# 暑假集训模拟赛 day4 (8.5)
## 前言
不好挂分了,也是荣誉拿下倒数好吧,我不爱写总结!
## 比赛基本情况
比赛日期 $2026.8.5$,比赛时常 $8:00-12:30$
预计分数:$100+100+20+60+0$
实际分数:$100+100+0+60+0$
代码源总榜排名:$rk100/292$
学校排名:$rk19/37$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 开A题,开始手玩找思路
- 8:20 想到一个解法,被自己hack了。
- 8:40 想到了正确写法。
- 9:10 提交A题通过,开B。
- 9:15 想到B题做法
- 9:20-10:30 写代码与调试中ing.
- 10:35 终于过大样例了,提交。
- 11:00 开始思考C打了个D暴力
- 11:30 开始打暴力。
- 12:30 比赛结束,遗憾离场
:::
整体感想:这次调题做题和思考用的时间太长了😥,并且C题还没有想出来,这场考试的题目与整体难度并不算难,也是唐完了🍭。
## 题目复盘
### A. 蜗是符文法师
我看到这种博弈论的题目就先往算贡献的方面想了😮。
一开始我思考对于每个1,他要几步才能到达最右边,可是我题目读错了😱,以为是 $0$ 变成 $1$,$1$ 变成 $0$ 所以浪费了很多时间😡。
后面才发现,对于每个操作,他要么是1往右走了两步,要么走了一步,那么这个问题就转换成小学博弈论了😋,我们就只用判断他是否可以配 $3$ 整除即可🙃。
小学知识,不详细证明😄。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
string s;int flag, n, sum, num;
signed main(){ cin >> s; n = s.size(), s = ' ' + s; for(int i = 1; i <= n; i++){ if(s[i] == '1') num++; else if(num) sum += num; } if(sum % 3 != 0) cout << "Yes" << '\n'; else cout << "No"; return 0;}```:::
### B. 蜗蜗的重力通道
这道题思路是一眼题,但是我们要思考如何卡常🤔。
对于这道题,因为他们的宽度最大都只有 $100$,所以我们很容易就可以造出一个 $dp$ 状态😦。$dp_{ij}$ 表示现在在第 $i$ 个块中,现在的高度是 $j$ 的方案数,转移我们就只用枚举高度差即可🤗。
但是我们发现我们转移需要求组合数,$T$ 有为 $100$ 所以我们需要预处理 $l_i$ 的阶乘👍,并且在美剧高度差的时候也要算阶乘,这样后面算组合数就可以用$O(1)$ 解决了,也不会出现 MLE 的情况👌。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 1e2 + 5, M = 998244353;
struct pp{ int sum, i, j;} zrr[MAXX * MAXX];
int n[MAXX], id[MAXX][MAXX], num[MAXX][MAXX], h[MAXX][MAXX], l[MAXX][MAXX], numf[MAXX][MAXX];int dp[MAXX][MAXX], inc[MAXX], inf[MAXX], cnt, op[MAXX][MAXX], T;
int qpow(int a, int b){ int res = 1; while(b){ if(b & 1) res = res * a % M; b >>= 1, a = a * a % M; } return res;}
void solve(int id){ memset(dp, 0, sizeof dp); for(int i = 1; i <= h[id][1]; i++) dp[1][i] = 1; for(int i = 1; i < n[id]; i++){ for(int j = 1; j <= h[id][i]; j++){ if(op[id][i] == 0){ int tmp = num[id][i]; for(int k = 0; k < j; k++){ if(k) tmp = tmp * (k + l[id][i]) % M; if((j - k) > h[id][i + 1]) continue; (dp[i + 1][j - k] += tmp * inf[k] % M * numf[id][i] % M * dp[i][j] % M) %= M; } }else{ int tmp = num[id][i]; for(int k = 0; k <= min(h[id][i + 1] - j, h[id][i] - j); k++){ if(k) tmp = tmp * (k + l[id][i]) % M; (dp[i + 1][j + k] += tmp * inf[k] % M * numf[id][i] % M * dp[i][j] % M) %= M; } } } } int ans = 0; for(int i = 1; i <= 100; i++) ans = (ans + dp[n[id]][i]) % M; cout << ans << '\n';}
bool cmp(pp a, pp b){ return a.sum < b.sum;}
signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> T; inc[0] = inf[0] = 1; for(int i = 1; i <= 101; i++){ inc[i] = inc[i - 1] * i % M; inf[i] = qpow(inc[i], M - 2); } for(int i = 1; i <= T; i++){ cin >> n[i]; for(int j = 1; j <= n[i]; j++){ cin >> l[i][j] >> h[i][j] >> op[i][j]; l[i][j]--; zrr[++cnt] = {l[j][i], i, j}; } n[i]++, l[i][n[i]] = 1, h[i][n[i]] = h[i][n[i] - 1]; } sort(zrr + 1, zrr + 1 + cnt, cmp); int tmp = 1, lst = 1; for(int i = 1; i <= cnt; i++){ while(lst <= zrr[i].sum) tmp = tmp * lst % M, lst++; num[zrr[i].i][zrr[i].j] = tmp, numf[zrr[i].i][zrr[i].j] = qpow(tmp, M - 2); } for(int i = 1; i <= T; i++) solve(i); return 0;}```:::
总而言之,这个代码就是坨#。
### C. 蜗蜗的魔法决斗榜
我一开始往数据结构去思考了,导致没有想到题目的关键,最后就只能打个最简单的暴力跑路了😶。
但是结构暴力都错了!
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 5e2 + 5;
int n, ans, t, k, q, zrr, a[MAXX][MAXX], vis[MAXX][MAXX], id, l, r;
void solve(){ cin >> n >> k >> q >> zrr; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) vis[i][j] = 0; for(int i = 1; i <= k; i++){ for(int j = 1; j <= n; j++){ cin >> a[i][j]; for(int k = 1; k < j; k++){'; vis[a[i][k]][a[i][j]] = 1; } } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(i == j || vis[i][j]) continue; for(int k = 1; k <= n; k++){ if(j == k || i == k) continue; if(vis[i][k] && vis[k][j]) vis[i][j] = 1; } } } while(q--){ ans = 0; cin >> id >> l >> r; for(int i = l; i <= r; i++){ for(int j = i + 1; j <= r; j++){ if(vis[a[id][i]][a[id][j]] == 1 && vis[a[id][j]][a[id][i]] == 1) ans++; } } cout << ans << '\n'; }}
signed main(){ cin >> t; while(t--) solve(); return 0;}```:::
经过中午TYK的指点也是明白了他那种很妙的方法🤪。
这题的关键是在想到分界点,若对于所有榜单的前 $i$ 列,刚好只有 $i$ 种数字,那么我们称其为分界点🤓。
我们可以知道对于两个相邻分界点设他们长度为 $L$ 他们可以造出的贡献为 $L (L - 1) / 2$ 个互相压制🤨。
这个东西我们可以用反证法证明,若两个元素 $x$ 和 $y$ 不是互相压制,我们设在所有榜单中 $x$ 在 $y$ 的上面,所以 $x$ 压制 $y$,那么肯定有一个 $k$ 使得在一个榜单中 $k$ 在他们两上面,一个榜单中 $k$ 在他们的下面,所以他们还是互相压制的。若不存在这样的 $k$ 那么它们两肯定不是相邻的😵。
我们又可以知道对于不同相邻分界点组成的区间之中,他们两是互相没有贡献的,证明读者自证不难😓。
所以题目就转换为对于一个区间 $[l,r]$ 我们要在他们中间找两个最边缘的分界点,然后里面的贡献可以用个前缀和处理,然后再处理一下两边的即可🤯。
### D. 蜗蜗的全一数
我却,python还是太好用了好吧,也是直接拿到了 $60$ 分的好成绩😍。
:::info[考场代码]```pythondef solve(): n = int(input()) h = n cnt = 0 while h > 0: cnt += 1 h = h // 10 ans = 0 for i in range(1, cnt + 1): tmp = 0 for j in range(1, i + 1): tmp = tmp * 10 + 1 if n % tmp == 0: ans = i print(ans)
t = int(input())for _ in range(t): solve()```:::
### E. CP连线大作战
感觉暴力也不好打,所以最后就没咋看了🙄。
:::info[考场代码]```cpp我说了我没写,你还打开干嘛!zrr so cute```:::
## 整体反思
我是唐😬,C题也是成功没想到,这也说明我的刷题还是太少了😦,其次我写代码和读题的时候并不是很细心,这也导致我调代码会用很长的时间,需要改进🙄。
# 暑假集训模拟赛 day4 (8.8)
## 前言
我吃柠檬,又挂分了,再次拿到倒数的好成绩。
## 比赛基本情况
比赛日期 $2026.8.8$,比赛时常 $8:00-12:30$
预计分数:$100+100+20+25+0$
实际分数:$100+100+0+25+0$
代码源总榜排名:$rk71/292$
学校排名:$rk17/37$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 比赛开始,开A。
- 8:10 想到解法,实践ing.
- 8:20 写完代码,写 Check。
- 8:40 通过 Check,提交开B。
- 9:00 想到了基础贪心思路,想如何构图。
- 9:45 终于想到了建图方法,实践
- 9:50-9:30 疯狂写代码ing.
- 9:40-11:00 调完代码,提交。
- 11:00-11:30 写D暴力。
- 11:30-12:00 写C暴力。
- 12:00 提前开溜,遗憾离场。
:::
整体感受:我靠今天的题目就是“食”🤢,两个题需要写 Check,其中还有一道是大数据结构,气笑了😤。今天依旧继承了上次的唐病,暴力都能Wa😠!
## 题目复盘
### A. 蜗蜗的魔法牌堆
这是一道类似诈骗题,写题前请看数据范围🙃。
因为我们可以的操作次数高达 $5e5$,我们便不由自主的对每个数字看其它需要的贡献😁。
我们发现若我们将一个数从开头移到结尾他的每次步数是递增的,那么对于每个数他的最坏的贡献只有 $log(n)$🤨 又因为 $n$ 只有 $1000$ 并且每个数字移动距离是越变越小的,我们直接暴力交换即可,时间完全充裕😄!
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 5e5 + 5;
struct pp{ int x, y;} ans[MAXX];
int n, a[MAXX], cnt;
int main(){ cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++){ int id = 0; for(int j = i; j <= n; j++){ if(a[j] == i){ id = j; break; } } while(id != i){ int tmp = min(id - i, n - id + 1); for(int j = id; j <= tmp + id - 1; j++) swap(a[j], a[id - tmp + (j - id)]); ans[++cnt] = {id - tmp, id + tmp - 1}; id = id - tmp; } } cout << cnt << '\n'; for(int i = 1; i <= cnt; i++) cout << ans[i].x << " " << ans[i].y << '\n'; return 0;}```:::
### B. 磁力实验
这题还是很有难度的🤔。我们可以发现磁和铁的配对可以只有两种情况:
1. 完全包含2. 不相交
因为如果他们有相交且没有完全包含的情况时,要么可以转变成完全包含,要么不相交更优(手玩一下即可)😜。
那么我们对于一个磁,如果它的左边有一个还没有匹配的铁,那么就可以将它们匹配(注意:要最近的😯)。同理,如果对于一个铁,如果他的左边有一个还没匹配的磁,那么也可以将他们匹配🤐。
这样我们就可以知道如何匹配的了,接下来我们要为启动顺序排序🤩。
我们发现如果他们匹配的不是最近的,那么我们发现会有一段区间的配对要在其之前完成抵消👌,那么我们可以用线段树维护 `topu` 的入度值,然后每次进栈,我们用线段数维护最小值,然后查找最小值为 $0$ 的点即可😕。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 2e5 + 5;
struct PP{ int minn, lazy;} t[MAXX * 4];
struct pp{ int op, x;} e[MAXX * 2];
int n, a[MAXX], b[MAXX], cnt, tot, h1, h2, p[MAXX], q[MAXX], num, id[MAXX], zrr[MAXX];queue<int> Q; vector<int> ans;
void pushup(int x){ t[x].minn = min(t[x * 2].minn, t[x * 2 + 1].minn);}
void update(int x, int l, int r){ if(!t[x].lazy) return; int mid = (l + r) / 2; t[x * 2].minn += t[x].lazy, t[x * 2 + 1].minn += t[x].lazy; t[x * 2].lazy += t[x].lazy, t[x * 2 + 1].lazy += t[x].lazy; t[x].lazy = 0;}
void add(int x, int l, int r, int L, int R, int w){ if(l > R || r < L) return; if(L <= l && r <= R){ t[x].minn += w, t[x].lazy += w; return; } update(x, l, r); int mid = (l + r) / 2; add(x * 2, l, mid, L, R, w), add(x * 2 + 1, mid + 1, r, L, R, w); pushup(x); }
void Find(int x, int l, int r){ if(t[x].minn) return; if(l == r){ t[x].minn = n + 1, Q.push(l); return; } update(x, l, r); int mid = (l + r) / 2; Find(x * 2, l, mid), Find(x * 2 + 1, mid + 1, r); pushup(x); }
bool cmp(pp a, pp b){ return a.x < b.x;}
signed main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; e[++cnt].op = n + i, e[cnt].x = a[i]; } for(int j = 1; j <= n; j++){ cin >> b[j]; e[++cnt].op = j, e[cnt].x = b[j]; } sort(e + 1, e + 1 + cnt, cmp); for(int i = 1; i <= cnt; i++){ if(e[i].op > n){ if(h1){ num += abs(e[p[h1]].x - e[i].x); id[e[i].op - n] = e[p[h1]].op, h1--; }else q[++h2] = i; }else{ if(h2){ num += abs(e[q[h2]].x - e[i].x); id[e[q[h2]].op - n] = e[i].op, h2--; }else p[++h1] = i; } } for(int i = 1; i <= n; i++){ int x = b[id[i]], y = a[i]; int tmp = abs(x - y); if(x < y){ int l = 1, r = i - 1, j = -1; while(l <= r){ int mid = (l + r) / 2; if(abs(x - a[mid]) <= tmp) j = mid, r = mid - 1; else l = mid + 1; } zrr[i] = j; if(j != -1) add(1, 1, n, j, i - 1, 1); }else{ int l = i + 1, r = n, j = -1; while(l <= r){ int mid = (l + r) / 2; if(abs(x - a[mid]) < tmp) j = mid, l = mid + 1; else r = mid - 1; } zrr[i] = j; if(j != -1) add(1, 1, n, i + 1, j, 1); } } Find(1, 1, n); while(!Q.empty()){ int x = Q.front(); Q.pop(); ans.push_back(id[x]); if(b[id[x]] < a[x]){ if(zrr[x] != -1) add(1, 1, n, zrr[x], x - 1, -1); }else{ if(zrr[x] != -1) add(1, 1, n, x + 1, zrr[x], -1); } Find(1, 1, n); } cout << num << '\n'; for(int i = (int)ans.size() - 1; i >= 0; i--) cout << ans[i] << " "; return 0;}```:::
还蛮好玩的😋,但就是有点“食”🤮。
### C. 符文奥秘
由于B题占用时间过多,直接打暴力😃!
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 1e5 + 5, M = 131, mod = 998244353, M2 = 97, mod2 = 1e9 + 7;
int a[MAXX], ans, n, t, k;map<pair<int, int>, int> mp;
void dfs(int x){ if(x > n){ int sum = 0; for(int i = 1; i <= k; i++) sum += a[i]; int tmp = sum, tmp2 = sum; for(int i = 2; i <= n; i++){ int zrr = (i + k - 1); if(zrr > n) zrr -= n; sum = sum - a[i - 1] + a[zrr]; tmp = (tmp * M + sum) % mod; tmp2 = (tmp2 * M2 + sum) % mod2; } if(!mp.count({tmp, tmp2})) mp[{tmp, tmp2}] = 1, ans++; return; } a[x] = 0; dfs(x + 1); a[x] = 1; dfs(x + 1);}
int main(){ cin >> t; cin >> n >> k; dfs(1); cout << ans << '\n'; return 0;}```:::
### D. 蜗蜗的符文树
由于B题占用时间过多,直接打暴力🙄!
然后最后暴力居然炸了🤣,也是直接损失 $25$ 分😭。
### E. 优先队列
压根没看😑!
## 整体反思
暴力又又又又又炸了🤬!今天的时间管理中平,主要是今天的B对我而言思维和代码都有一点点难,但是这种题还是蛮好玩的🤡。
然后今天第三题其实还好,但是我对数学的敏感度还是不足😥,有待提升空间。其次暴力的正确度也要提升🚀。
# 暑假集训模拟赛 day5 (8.10)
## 前言
今天的题目也是非常的“食”💩,一上午都在改 B👿。连暴力都没时间写了,实则是没心情写了😵。哈哈哈哈哈!TYK A没删调试😜!
## 比赛基本情况
比赛日期 $2026.8.10$,比赛时常 $8:00-12:30$
预计分数:$100+100+20+0+0$
实际分数:$100+100+20+0+0$
代码源总榜排名:$rk65/300$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 开A题,10分钟左右想到思路
- 8:40 过了所有样例。
- 8:50 发现答案统计错误,思考如何处理。
- 9:10 想到新的解法,实践。
- 9:30 再次过了所有数据,提交开B。
- 9:40 想到解法,开始实践。
- 10:00 写完代码,开始调试。
- 10:20 找到第一个错误。
- 10:40 找到第二个错误。
- 10:45 找到第三个错误。
- 11:05 找到第四个错误。
- 11:20 找到第五个错误。
- 11:30 过了所有样例,提交。
- 12:00 打完了C题暴力,直接摆烂。
- 12:30 比赛结束
:::
整体感想:我讨厌改题😡,B题搬题人是ZRR,A也是恶心题,CCH还说是好题🤬!?感觉时间还是不太够用,总体时间分配也不平均🙄,也是跟B杠上了好吧!只能说至少今天没挂分😔。
## 题目复盘
### A. 对称风铃
前景提要:这一题有坑,需要多想一下🤔!
对于他的操作次数我们很好解决,就是对于每个线看他平行的有多少根😁,又因为绳子挂的点都不相同,所以我们很容易就可以想到,一定有方案可以使得每个绳子最多动一下👌。
那么我们问题就可以转换为如何解决约束矛盾的问题,其实也并不难,我们可以考虑建图来解决约束🙂,如果对于一个点他的一个断点的对应点属于一条线的点,那么这两条线就不能同时选了这条平行于标准的线,那么又因为所有点不同,边数与时间复杂度完全不会爆🤨!
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 1e6 + 5;
struct pp{ int x, y, z;} ans[MAXX];
int n, x[MAXX], y[MAXX], minn = INT_MAX, cnt, sum[MAXX], ID, vis[MAXX], X[MAXX], Y[MAXX], zrr, id[MAXX];vector<pair<int, int> > e[MAXX][2];
void dfs(int u, int id){ if(vis[u]) return; if(id == 0) ans[++cnt] = {u, y[u], Y[u]}; else ans[++cnt] = {u, x[u], X[u]}; vis[u] = 1; for(int i = 0; i < e[u][id].size(); i++){ dfs(e[u][id][i].first, e[u][id][i].second); }}
signed main(){ freopen("popipa.in", "r", stdin); freopen("popipa.out", "w", stdout); cin >> n; for(int i = 0; i < n; i++){ cin >> x[i] >> y[i]; sum[(x[i] + y[i]) % (2 * n)]++; id[x[i]] = id[y[i]] = i; } for(int i = 0; i < 2 * n; i++){ int tmp = n - sum[(i + ((i + 1) % (2 * n))) % (2 * n)]; if(tmp < minn) ID = (i + ((i + 1) % (2 * n))) % (2 * n), minn = tmp; } for(int i = 0; i < n; i++){ if((x[i] + y[i]) % (2 * n) == ID){ vis[i] = 1; continue; } zrr = i; Y[i] = (x[i] <= ID ? ID - x[i] : (ID + 2 * n) - x[i]); X[i] = (y[i] <= ID ? ID - y[i] : (ID + 2 * n) - y[i]); if(x[id[Y[i]]] == Y[i]) e[i][0].push_back({id[Y[i]], 1}); else if(y[id[Y[i]]] == Y[i]) e[i][0].push_back({id[Y[i]], 0}); if(x[id[X[i]]] == X[i]) e[i][1].push_back({id[X[i]], 1}); else if(y[id[X[i]]] == X[i]) e[i][1].push_back({id[X[i]], 0}); } for(int i = 0; i < n; i++){ if(!vis[i]) dfs(i, 0); } cout << cnt << '\n'; for(int i = 1; i <= cnt; i++){ cout << ans[i].x << " " << ans[i].y << " " << ans[i].z << '\n'; } return 0;}```:::
### B. 魔法石共鸣
这题也是与第一天的A非常的像好吧😍!但是调了我很久😨。
我们直接套路按位考虑,我们从高位往低位思考,如果有 $1$ 那么我们肯定我们要把 $1$ 放一边是最优的,所以我们就有了个基础贪心策略😄。
1. 我们先从最高位考虑,分到两个队列里面。
2. 对于现在这个位,如果为 $1$ 的序列里面的数这个位有 $1$,那么我们就将 $0$ 的序列中这个位为 $1$ 的数塞到 $1$ 序列中。
3. 对于现在这个位,如果为 $1$ 的序列里面的数这个位没 $1$,那么我们就将 $0$ 的序列中所有这个位为 $1$ 的数合并,使得他们永远都捆绑在一起,维护答案(合并也就是直接或运算即可)。
备注:这个代码需要处理很多例如边界😑,序列不为空的情况,也是写了我很久好吧🤮!
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 4e5 + 5;
int a[MAXX], n, t, ans, vis[MAXX], k, tot;
void solve(){ cin >> n; ans = k = tot = 0; for(int i = 1; i <= n; i++){ cin >> a[i], vis[i] = 0; } sort(a + 1, a + 1 + n); int tmp = a[n]; while(tmp) tmp /= 2, k++; for(; k >= 1; k--){ int num = 0; for(int i = 1; i <= n; i++) num += ((a[i] >> (k - 1)) & 1); if(num < n && num != 0){ for(int i = 1; i <= n; i++) if((a[i] >> (k - 1)) & 1) vis[i] = 1, tot++; ans = (1 << (k - 1)), k--; break; } } for(; k >= 1 && tot < n - 1; k--){ int num = 0; for(int i = 1; i <= n; i++) if(vis[i] == 1) num += ((a[i] >> (k - 1)) & 1); if(num){ int xyz = 0; for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) xyz++; if(tot + xyz == n) continue; for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) vis[i] = 1, tot++; ans += (1 << (k - 1)); }else{ int zrr = 0; for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) zrr = i; if(!zrr) continue; for(int i = 1; i < zrr; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) vis[i] = 2, a[zrr] |= a[i], tot++; ans += (1 << (k - 1)); } } for(; k >= 1; k--){ int num1 = 0, num2 = 0; for(int i = 1; i <= n; i++) if(vis[i] == 1) num1 += ((a[i] >> (k - 1)) & 1); for(int i = 1; i <= n; i++) if(vis[i] == 0) num2 += ((a[i] >> (k - 1)) & 1); if((num1 && !num2) || (!num1 && num2)) ans += (1 << (k - 1)); } cout << ans << '\n';}
signed main(){ freopen("magic.in", "r", stdin); freopen("magic.out", "w", stdout); cin >> t; while(t--) solve(); return 0;}```:::
### C. 能量核心共鸣
这道题直接写暴力好吧😶。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int unsigned long long
using namespace std;
const int MAXX = 5e3 + 5;
int op[MAXX], l[MAXX], r[MAXX], x[MAXX], a[MAXX], n, q, ans, sum[MAXX], num[MAXX];
void solve1(){ for(int i = 1; i <= q; i++){ cin >> op[i]; if(op[i] == 1){ cin >> l[i] >> r[i] >> x[i]; for(int j = l[i]; j <= r[i]; j++) a[j] &= x[i]; }else if(op[i] == 2){ cin >> l[i] >> x[i]; a[l[i]] = x[i]; }else{ cin >> l[i] >> r[i]; sum[l[i]] = a[l[i]], num[r[i]] = a[r[i]]; for(int j = l[i] + 1; j <= r[i]; j++) sum[j] = sum[j - 1] & a[j]; for(int j = r[i] - 1; j >= l[i]; j--) num[j] = num[j + 1] & a[j]; ans = max(num[l[i] + 1], sum[r[i] - 1]); for(int j = l[i] + 1; j < r[i]; j++) ans = max(ans, sum[j - 1] & num[j + 1]); cout << ans << '\n'; } }}
void solve2(){ int sum1 = 0, sum2 = 0, sum3 = 0; for(int i = 1; i <= q; i++){ cin >> op[i]; if(op[i] == 1){ sum1++; cin >> l[i] >> r[i] >> x[i]; }else if(op[i] == 2){ sum2++; cin >> l[i] >> x[i]; }else{ sum3++; cin >> l[i] >> r[i]; } }}
signed main(){ freopen("energy.in", "r", stdin); freopen("energy.out", "w", stdout); cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i]; if(n <= 5000) solve1(); else solve2(); return 0;}```:::
### D. 蜗蜗的零件仓库
这题不想看了,呜呜呜呜😭!
### E. 加一2.5
这题不想看了,呜呜呜呜😭!
## 整体反思
时间还是不够,调试代码能力太弱了😥,写代码也不够细心,做题前没有考虑代码的正确性😣。
其次我还是太菜了,没有能力考高分😟。
哎~菜就多练吧🏀!
# 暑假集训模拟赛 day6 (8.13)
## 前言
妈的今天又挂分了😡,足足挂了 $100$ 分,妈的我就是傻逼🤬。
:::error[比赛感想]我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。
我是傻逼🤬。:::
## 比赛基本情况
比赛日期 $2026.8.13$,比赛时常 $8:00-12:30$
预计分数:$100+100+100+0$
实际分数:$100+100+0+0$
代码源总榜排名:$rk150/300$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 开始做A。
- 8:10 想到一个错解
- 8:20 写了一半发现贪心有问题,改写法。
- 8:30 换写法。
- 8:50 过了所有样例提交,开B。
- 9:20 发现时间复杂度的特点。
- 9:30 想到写法
- 10:05 过了所有样例提交,开C。
- 10:10-11:40 思考ing.
- 11:45 想到正确写法,实践。
- 12:25 输出长度正确,提交。
- 12:30 公布成绩,遗憾离场。:::
整体感想:我是傻子😤,这次题目整体比较简单,而且只有四道题,我却考炸了😩。最后一次模拟赛也是遗憾离场好吧😞!呜呜呜呜😭。
## 题目复盘
### A. 蜗蜗的能量水晶
这一道题是送分题,我们先将数组排序,因为我们要让它的值最小所以我们可以想到最基础的贪心:我们只会选连续的两个数,这样才是最优的👍。
那我们直接选前 $n$ 小的即可吗🤔?
不是,因为对于选的数,他是有一个限制的。因为是最小值做差,我们若选的数字非常的后面这会导致我往里面塞的其他数太小了😮,所以对于我们选的第 $i$ 个数有区间 $[1,1+(i-1) \times 2k]$ 🤨。其实这里可以直接发现单调性二分答案,我一开始写了个线段树,贪心找点会影响两边的答案,会出问题,糖糖🍭。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 1e6 + 5;
int n, k, a[MAXX], num[MAXX], ans, N;
bool check(int x){ int cnt = 0; for(int i = 1; i <= N; i++){ if(num[i] <= x){ cnt++; if(i > 1 + (cnt - 1) * 2 * k) return 0; i++; } } return cnt >= n;}
signed main(){ freopen("crystal.in", "r", stdin); freopen("crystal.out", "w", stdout); cin >> n >> k; N = 2 * n * k - 1; for(int i = 1; i <= 2 * n * k; i++) cin >> a[i]; sort(a + 1, a + 1 + 2 * n * k); for(int i = 1; i <= N; i++) num[i] = a[i + 1] - a[i]; int l = 0, r = 1e9; while(l <= r){ int mid = (l + r) / 2; if(check(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans << '\n'; return 0;} ```:::
### B. 观星
这道题我们可以惊奇的发现😯,他 $n,m$ 的总和不超过 $2000$ 所以综合一下 $t = 10$ 左右,所以 $nm^2$ 的时间复杂度完全可以过😍。
我们发现一个性质:一个人顺时针走,一个人逆时针走,且两个人步数相同,又因为这是一个环所以所有人的坐标值和再取模 $m$ 是不变的🤯,那么我们就可以写 DP 了,剩下步骤啥子都会写😊。
这道题的主要难点就是找到这个性质😄。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 2e2 + 5;
int n, m, k, a[MAXX], sum, h[MAXX][MAXX], dp[MAXX][MAXX], t, X;
void solve(){ cin >> n >> m >> X; for(int i = 1; i <= n; i++){ cin >> a[i]; a[i]--; sum += a[i]; } for(int i = 1; i <= n; i++){ for(int j = 0; j < m; j++) cin >> h[i][j]; } sum %= m; memset(dp, -0x7f, sizeof dp); dp[0][sum] = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j < m; j++){ if(dp[i - 1][j] == dp[0][m + 1]) continue; for(int k = 0; k <= m; k++){ int tmp = k * X % m; dp[i][(j + tmp + m) % m] = max(dp[i][(j + tmp + m) % m], dp[i - 1][j] + h[i][(a[i] + tmp) % m]); dp[i][(j - tmp + m) % m] = max(dp[i][(j - tmp + m) % m], dp[i - 1][j] + h[i][(a[i] - tmp + m) % m]); } } } cout << dp[n][sum] << '\n';}
signed main(){ freopen("liel1a.in", "r", stdin); freopen("liel1a.out", "w", stdout); cin >> t; while(t--) solve(); return 0;}```:::
### C. 生日聚会
由于这个题目搭档保证唯一,我们先思考如何求搭档🤨。
对于一个点如果他现在出度为 $1$ 那么他与其连边。又由于题目保证其图是一个类似的二分图所以不存在基环,因此可以用 topu 就一定可以配对,这样搭档就求出来了😏,那么我们思考如何找连续的😶。
我一开始是这么想的,我们直接把搭档缩成一个点,然后再跑图。但是我们可以发现,如果这样子就不能保证其一定经过搭档边,所以还需改进😐。
但是如果我们构造的图就让他经过这条边即可,因此我想到了新的构图方法👌。
$$\newcommand{\px}[1]{\color{#1}{\rule{6pt}{6pt}}} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ef7d57} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{ffffff} \px{ffffff} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt]\px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{ffffff} \px{ffffff} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt]\px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt]\px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ef7d57} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ffffff} \px{1a1c2c} \px{1a1c2c} \px{73eff7} \px{73eff7} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt]$$
我们对于两个搭档点绿和黄,我们直接跨过绿连接绿的邻节点,就如图中橙色连边。由于缩点性质不变依然可以跑 topu 排序👍。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 2e6 + 5;
int n, m, in[MAXX], vis[MAXX], pre[MAXX], ans[MAXX], tot, u, v, id[MAXX], cnt, flag[MAXX], dp[MAXX], maxx, ID;pair<int, int> num[MAXX];vector<int> e[MAXX], G[MAXX];queue<int> q, Q;
signed main(){ freopen("party.in", "r", stdin); freopen("party.out", "w", stdout); cin >> n >> m; n *= 2; for(int i = 1; i <= m; i++){ cin >> u >> v; e[u].push_back(v), e[v].push_back(u); in[u]++, in[v]++; } for(int i = 1; i <= n; i++){ if(in[i] == 1) q.push(i); } while(!q.empty()){ int x = q.front(); q.pop(); for(int i = 0; i < e[x].size(); i++){ int y = e[x][i]; if(!id[y]){ id[x] = y, id[y] = x; for(int j = 0; j < e[id[x]].size(); j++){ in[e[id[x]][j]]--; if(in[e[id[x]][j]] == 1) q.push(e[id[x]][j]); } } } } for(int i = 1; i <= n; i++){ for(int j = 0; j < e[id[i]].size(); j++){ int y = e[id[i]][j]; if(y == i) continue; G[i].push_back(y); flag[y]++;// cout << i << " " << y << '\n'; } } for(int i = 1; i <= n; i++){ if(flag[i] == 0) Q.push(i); } while(!Q.empty()){ int x = Q.front(); Q.pop(); dp[x] += 2;// cout << x << " | " << dp[x] << '\n'; if(dp[x] > maxx) maxx = dp[x], ID = x; for(int i = 0; i < G[x].size(); i++){ int y = G[x][i]; flag[y]--; if(dp[y] < dp[x]) pre[y] = x, dp[y] = dp[x]; if(flag[y] == 0) Q.push(y); } } while(ID != 0){ ans[++tot] = ID; ans[++tot] = id[ID]; ID = pre[ID]; } cout << tot << '\n'; for(int i = tot; i >= 1; i--) cout << ans[i] << " "; return 0;}```:::
:::info[AC代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 2e6 + 5;
int n, m, in[MAXX], vis[MAXX], pre[MAXX], ans[MAXX], tot, u, v, id[MAXX], cnt, flag[MAXX], dp[MAXX], maxx, ID;pair<int, int> num[MAXX];vector<int> e[MAXX], G[MAXX];queue<int> q, Q;
signed main(){// freopen("party.in", "r", stdin);// freopen("party.out", "w", stdout); cin >> n >> m; n *= 2; for(int i = 1; i <= m; i++){ cin >> u >> v; e[u].push_back(v), e[v].push_back(u); in[u]++, in[v]++; } for(int i = 1; i <= n; i++){ if(in[i] == 1) q.push(i); } while(!q.empty()){ int x = q.front(); q.pop(); for(int i = 0; i < e[x].size(); i++){ int y = e[x][i]; if(!id[y]){ id[x] = y, id[y] = x; for(int j = 0; j < e[id[x]].size(); j++){ in[e[id[x]][j]]--; if(in[e[id[x]][j]] == 1) q.push(e[id[x]][j]); } } } } for(int i = 1; i <= n; i++){ for(int j = 0; j < e[id[i]].size(); j++){ int y = e[id[i]][j]; if(y == i) continue; G[i].push_back(y); flag[y]++;// cout << i << " " << y << '\n'; } } for(int i = 1; i <= n; i++){ if(flag[i] == 0) Q.push(i); } while(!Q.empty()){ int x = Q.front(); Q.pop(); dp[x] += 2;// cout << x << " | " << dp[x] << '\n'; if(dp[x] > maxx) maxx = dp[x], ID = x; for(int i = 0; i < G[x].size(); i++){ int y = G[x][i]; flag[y]--; if(dp[y] < dp[x]) pre[y] = x, dp[y] = dp[x]; if(flag[y] == 0) Q.push(y); } } while(ID != 0){ ans[++tot] = id[ID]; ans[++tot] = ID; ID = pre[ID]; } cout << tot << '\n'; for(int i = tot; i >= 1; i--) cout << ans[i] << " "; return 0;}```:::
没错就是因为输出顺序导致的,还我 $100$ 分🙁。
### D. 蜗蜗的星际帝国
C 题都没调出来写个蛋啊😢!
## 整体反思
今天挂了本学期最多的一次挂分,也是荣誉再次拿下倒数了😨。
感觉自己的思维和对算法的运用能力还要加强😑。
自我感觉粗心错误以无药可救💀。