版本比较
代码源考试总结(全集)
正文
增加 1852 行删除 0 行
318 行未改动全部展开31932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174318 行未改动全部展开
## 整体反思
这场比赛我的代码正确率比较高😁,其次这次比赛状态还可以。但是时间安排与代码暴力能力上还有很多进步空间🤡。
# 暑假集训模拟赛 day2 (7.31)
## 前言
死磕T2没有写出来😡,变成祝睿融了🐽,也是被别人暴打了好吧😭!
## 比赛基本情况
比赛日期 $2026.7.31$,比赛时常 $8:00-12:30$
预计分数:$100+20+0+10+0$
实际分数:$100+40+0+10+0$
代码源总榜排名:$rk119/292$
学校排名:$rk19/37$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 开A题,5分钟左右想到解法,实践
- 8:45 过了所有的小样例,但是大样例错了
- 8:50 发现建图错误,改写发
- 9:00 大样例还是错了,继续坐牢
- 9:15 发现 $x$ 写成 $y$ 了,大样例过了提交,开始写B题。
- 9:40 - 11:40 死磕B题中写了两种写法,拼尽全力无法战胜
- 11:55 没时间了,写了D题暴力提交
- 12:10 发现时间不够,摆烂了
- 12:30 比赛结束
:::
整体感想:今天也是孬爆了,B题都没写出来😤,整体题目难度比上次简单一点但是由于时间分配没有太多时间思考了😒。个人能力还是需要加强🐱🏍。
## 题目复盘
### A. 项目分组
第一题也是非常的简单好吧,也是一眼就想到了解法🤪。我们可以先思考不合理的情况:
- 如果超过两个一样的数,那么他就不合法。
- 如果三个及以上的数有相同的因数他也不合法。
- 如果两个数有共同的因数那么他们一定不能在一个集合。
那么前面两个可以直接用枚举质数解决,那么第二个我们可以用给图染色解决😮。
又因为对于每个质数,他最多有两个倍数才合法,那么边的数量是完全不会超的🤤,那么我们找倍数又是一个 $log$ 时间复杂度的,$t$ 又很小完全可以做好吧😛!
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 2e6 + 5, INF = 2e6 + 1;
int n, sum[MAXX], a[MAXX], sum1, sum0, vis[MAXX], flag, t, cnt, prime[MAXX], num[MAXX];vector<int> e[MAXX], G[MAXX], zrr1, zrr0, ans, xyz;
void init(){ for(int i = 1; i <= n; i++) sum[a[i]]--, e[a[i]].clear(); for(int i = 1; i <= n; i++) G[i].clear();}
void dfs(int x, int col){ if(flag) return; vis[x] = col; if(col) sum1++, zrr1.push_back(x); else sum0++, zrr0.push_back(x); for(int i = 0; i < G[x].size(); i++){ int y = G[x][i]; if(vis[y] == -1) dfs(y, 1 - col); if(vis[y] == vis[x]){ flag = 1; return; } }}
void solve(){ cin >> n; ans.clear(); for(int i = 1; i <= n; i++) vis[i] = -1; for(int i = 1; i <= n; i++) cin >> a[i], sum[a[i]]++, e[a[i]].push_back(i); for(int i = 1; i <= n; i++){ if(sum[a[i]] > 2){ cout << -1 << '\n'; init(); return; } } for(int i = 1; i <= cnt; i++){ int tmp = prime[i]; xyz.clear(); for(int j = tmp; j <= INF; j += tmp){ for(int k = 0; k < e[j].size(); k++) xyz.push_back(e[j][k]); } for(int j = 0; j < xyz.size(); j++){ for(int k = 0; k < xyz.size(); k++){ if(j != k) G[xyz[j]].push_back(xyz[k]); } } if(xyz.size() > 2){ cout << -1 << '\n'; init(); return; } } for(int i = 1; i <= n; i++){ if(vis[i] == -1){ zrr0.clear(), zrr1.clear(), flag = sum0 = sum1 = 0; dfs(i, 0); sort(zrr0.begin(), zrr0.end()), sort(zrr1.begin(), zrr1.end()); if(flag){ cout << -1 << '\n'; init(); return; } if(sum0 < sum1 || (sum1 == sum0 && zrr1[0] < zrr0[0])) for(int j = 0; j < zrr1.size(); j++) ans.push_back(zrr1[j]); else if(sum0 > sum1 || (sum1 == sum0 && zrr1[0] > zrr0[0])) for(int j = 0; j < zrr0.size(); j++) ans.push_back(zrr0[j]); } } cout << ans.size() << '\n'; sort(ans.begin(), ans.end()); for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << '\n'; init();}
int main(){ ios::sync_with_stdio(0); cin.tie(0); for(int i = 2; i <= INF; i++){ if(num[i] == 0) prime[++cnt] = i; for(int j = i * 2; j <= INF; j += i) num[i] = 1; } cin >> t; while(t--) solve(); return 0;} ```:::
### B. 信号清晰度分析
考场思路:我发现通过枚举01分界线似乎可以更好的算答案🤔,然后对于01分界点我们找到最左边的点使得其到中点的所有后缀和他的 $0$ 多于 $1$ 的数量,同理找到一个最右的点使得他的前缀和的 $1$ 多于 $0$ 的数量🤨。那么我们就可以用单调栈解决😯。
但是他的答案并不是很好维护,所以没有想好完整代码就开始实践,浪费了很多时间😥。最终只能写一个暴力放上去,居然还有40分😏。
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 1e7 + 5;
int n, a[MAXX], ans, t, num[MAXX];char ch;
void solve(){ cin >> n; ans = 0; for(int i = 1; i <= n; i++) cin >> ch, a[i] = (ch == '0' ? 0 : 1); for(int i = 1; i <= n; i++) num[i] = num[i - 1] + (a[i] == 0); for(int i = 1; i <= n; i++){ for(int j = i; j <= n; j++){ int maxx = 0; for(int k = i - 1; k <= j; k++) maxx = max(maxx, (num[k] - num[i - 1] + (j - k) - (num[j] - num[k]))); ans += maxx; } } cout << ans << '\n';}
signed main(){ cin >> t; while(t--) solve(); return 0;}```:::
正解思路:DFbd的做法太强了👍!膜拜谭云开。
对于这道题,我们要求总最长上升子序列的长度,又因为只有 $0$ 和 $1$。所以我们可以考虑每一个点对于序列的贡献,所以我们固定右端点来思考做法😦。
对于一个已选出来的以 $1$ 结尾最长上升子序列,我们如果不把 $1$ 删掉那么我们就只能放 $1$,如果放 $0$ 的话那么我们就会有代价,代价就为结尾 $1$ 的数量减去可以放的 $0$ 的数量😶。那么我们知道一个重要的性质:如果它将 $1$ 换成 $0$ 的代价为 $0$ 的时候优先换,因为以 $0$ 结尾的序列有更多的空间😏,这就可以保持上升序列最长。
接下来我们通过举例子的方法来思考下一步的做法。对于一个序列 $011110001$ 我们可以试图写出每个左端点对右端点的加贡献。
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 ||:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|| +1 | | | | | | | | || +1 | +1 | | | | | | | || +1 | +1 | +1 | | | | | | || +1 | +1 | +1 | +1 | | | | | || +1 | +1 | +1 | +1 | +1 | | | | || | | | | +0 | +1 | | | || | | | +0 | +1 | +1 | +1 | | || | | +0 | +1 | +1 | +1 | +1 | +1 | || +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 |
注释:其中+0是指抵消的值(就是上文代价为 $0$)。
我们可以发现他的贡献是连续的,我们可以通过反证法来证明。如果不是连续的,又他们的两段贡献的中间就一定有 $0$。所以不成立😇,虽然这个没有什么用😝。
然后我会学习deekseep将核心代码逐行讲解🐋。
我们维护 $end0$ 只以 $0$ 为结尾的子序列数量。
$num$ 为以 $i$ 为右节点的贡献。
$end1[i]$ 维护以 $1$ 结尾的数且当前代价为 $i$ 可以替换的子序列数量。
$val$ 只的是现在的需要的代价。
- 对于当前节点为 $0$ 的时候,我们就可以增加一个结尾为 $0$ 的数量,同时 $0$ 可以为所有以 $0$ 结尾的数做一次贡献。同时我们可以将之前为当前代价时存入的数直接拿走,同时更新当前代价。- 对于当前节点为 $1$ 的时候,我们现在的代价会增加,同时这个 $1$ 会接到所有以 $0$ 结尾的数后面所以我们将其存入当前代价的数组中,为下一次替换做准备。同时更新答案和变量。
核心代码:```cpp for(int i = 1; i <= n; i++){ cin >> ch; if(ch == '0'){ end0++, num += end0, end0 += end1[val]; end1[val] = 0, val = max(0, val - 1); }else{ end1[++val] += end0 + 1; num += i, end0 = 0; } ans += num; }```
是不是很神奇,当然也很绕😵,我是DFbd,太强啦🤯!
### C. 蜗蜗的数字迷宫
考试时来不及看了🙄
### D. 沙海奥秘
我看这题暴力最好写,写了个暴力便走人了🤩。
:::info[赛事代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 1e7 + 5;
int n, a[MAXX], ans, q;char ch;
void solve(){ cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i]; int INF = a[(n + 1) / 2]; for(int i = 0; i <= INF; i++){ for(int j = i + 1; j <= INF; j++){ bool flag = 1; for(int k = 1; k <= n / 2; k++){ if(min(j - i, max(0ll, a[k] - i)) != min(j - i, max(0ll, a[n - k + 1] - i))) flag = 0; } ans += flag; } } cout << ans << '\n';}
signed main(){ int t = 1; while(t--) solve(); return 0;}```:::
### E. 排列
考试时来不及看了🙄
## 整体反思
这场比赛没有挂分,但是还是太菜了,B题没有写出来,哇哇哇哇🤬。个人能力还需增强,暴力能力与时间管理还有很大的进步空间🤫。
# 暑假集训模拟赛 day3 (8.2)
## 前言
妈的,我是傻逼,他妈又唐了🍭。T3那么简单居然没有调出来🤬!又是吃屎的一天🤮。
## 比赛基本情况
比赛日期 $2026.8.2$,比赛时常 $8:00-12:30$
预计分数:$100+100+30+0+0$
实际分数:$100+100+30+0+0$
代码源总榜排名:$rk81/300$
学校排名:$rk14/37$
## 比赛整体回顾
:::info[具体做题时间]
- 8:00 开始做题,手玩A题。
- 8:10 推出假做法,被自己hack了
- 8:15-8:25 肚子不舒服,去上厕所了。
- 8:30 重新想到正确做法。
- 8:40 做完题目并提交,开B
- 9:00 想到了求区间并用线段数维护,开始写代码。
- 9:40 过了所有大数据,提交,看C。
- 9:50 一开始只想到了是数位dp但是需要二位状态,先写了暴力。
- 10:10 发现B题维护好像出了些问题,想新的思路,开始双线程做题。
- 10:50 想到了新的做法,开始实践。
- 11:30 B题又过了大样例,提交。
- 11:40 开始写C题新做法
- 12:10 C过不了大样例,只好交暴力,没有做题欲望了。
- 12:30 比赛结束。
:::
**整体感想**:今天也是唐飞了好吧!还有这B题样例也太水了吧,差评👎!今天的时间又又又又又不够,而且很简单的思路思考时间比较久😔。
## 题目复盘
### A. 蜗蜗的魔法手环
这一道题是一个大分讨题目,我是通过手玩来写的😊。
通过发现我们可以轻松的得出以下结论😋:
- 1. 当只有一种字母的时候一定无解(xyz都知道😏)- 2. 当有两种情况的时候: - 2.1. 若小的那种字母它的个数小于二的时候误解😮(重复的是 $aaab$ 或 $aaaa$) - 2.2. 如果大于三个那么不能有连续 $n / 2$ 个 $a$ 在一起有不能有同样数量的 $a$ 在接上同样数量的 $b$。那么很容易想到把 $a$ 分成两半,第一半后面接一个 $b$ 另一个后面接一个 $c$🧐。- 当有三个及以上种情况的时候我们应该也像 2.2 一样的思路构造,不太多说明😀。
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 1e3 + 5;
string s;int sum[MAXX], maxx, id, num;vector<int> e;
int main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> s; int n = s.size(); s = ' ' + s; for(int i = 1; i <= n; i++) sum[int(s[i] - 'a' + 1)]++; for(int i = 1; i <= 26; i++){ if(maxx < sum[i]) maxx = sum[i], id = i; num += (bool)(sum[i]); } if(num == 1){ cout << "NO"; return 0; }else if(num == 2){ if(maxx > n / 2){ if(maxx >= n - 2){ cout << "NO"; return 0; }else{ cout << "YES" << '\n'; for(int i = 1; i <= 26; i++){ if(i == id) continue; while(sum[i]--) e.push_back(i); } for(int i = 1; i <= maxx / 2 - 1; i++) cout << char('a' + id - 1); cout << char('a' + e[0] - 1); for(int i = maxx / 2; i <= maxx; i++) cout << char('a' + id - 1); for(int i = 1; i < e.size(); i++) cout << char('a' + e[i] - 1); } }else{ cout << "YES" << '\n'; for(int i = 1; i <= 26; i++){ while(sum[i]--) cout << char('a' + i - 1); } } }else{ cout << "YES" << '\n'; for(int i = 1; i <= 26; i++){ if(i == id) continue; while(sum[i]--) e.push_back(i); } for(int i = 1; i <= maxx / 2; i++) cout << char('a' + id - 1); cout << char('a' + e[0] - 1); for(int i = maxx / 2 + 1; i <= maxx; i++) cout << char('a' + id - 1); for(int i = 1; i < e.size(); i++) cout << char('a' + e[i] - 1); } return 0;} ```:::
### B. 蜗蜗的舒适旋律
**前景提要**:我写的错的解法能过大样例,这大样例使用脚趾造的吗🤐!
**赛时思考1**
因为我们要求对于一个数最左边小于它的数且两数中间有一个数的值在他们两个数构造的值域之内🤔。
所以我想当然了直接求对于一个数第一个小于等于他的数,然后递归两边我就以为这样就行了😶,然后用线段树维护也为维护个错的,但是过了大样例❓。
**赛时思考2**
因为发现前面的想法错了,被迫换了写法😣。这次我们不直接递归而是枚举其两边的数用单调栈求😕。然后就有了一个正确的区间。那么只需要我们用线段树维护二位偏序即可🙂。
:::info[考场代码]```cpp#include<bits/stdc++.h>
using namespace std;
const int MAXX = 4e5 + 5;
struct pp{ int op, l, r, id;} e[MAXX];
int n, q, a[MAXX], l, r, t[MAXX * 4], id1[MAXX], id2[MAXX], arr[MAXX], h[MAXX], cnt, num[MAXX], T, ans[MAXX];
void pushup(int x){ t[x] = min(t[x * 2], t[x * 2 + 1]);}
void build(int x, int l, int r){ if(l == r){ t[x] = n; return; } int mid = (l + r) / 2; build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r); pushup(x);}
void add(int x, int l, int r, int L, int val){ if(l > L || r < L) return; if(l == r && l == L){ t[x] = min(t[x], val); return; } int mid = (l + r) / 2; add(x * 2, l, mid, L, val); add(x * 2 + 1, mid + 1, r, L, val); pushup(x);}
int answer(int x, int l, int r, int L, int R){ if(l > R || r < L) return n; if(L <= l && r <= R) return t[x]; int mid = (l + r) / 2; return min(answer(x * 2, l, mid, L, R), answer(x * 2 + 1, mid + 1, r, L, R));}
bool cmp(pp a, pp b){ if(a.r != b.r) return a.r < b.r; return a.op < b.op;}
int main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> T; while(T--){ cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i], num[i] = 0; cnt = 0; for(int i = n; i >= 1; i--){ while(cnt && a[h[cnt]] >= a[i]) id1[h[cnt]] = i, cnt--; h[++cnt] = i; } while(cnt) id1[h[cnt]] = -1, cnt--; cnt = 0; for(int i = 1; i <= n; i++){ while(cnt && a[h[cnt]] <= a[i]) id2[h[cnt]] = i, cnt--; h[++cnt] = i; } while(cnt) id2[h[cnt]] = -1, cnt--; for(int i = 1; i <= n; i++){ if(id1[i] == -1 || id2[i] == -1) continue; else e[++cnt] = {0, id1[i], id2[i], 0}; } build(1, 1, n); for(int i = 1; i <= q; i++) cin >> l >> r, e[++cnt] = {1, l, r, i}; sort(e + 1, e + 1 + cnt, cmp); for(int i = 1; i <= cnt; i++){ if(e[i].op == 0) add(1, 1, n, e[i].l, (e[i].r - e[i].l + 1 - 3)); else{ int tmp = answer(1, 1, n, e[i].l, e[i].r); if(tmp >= n) ans[e[i].id] = -1; else ans[e[i].id] = (e[i].r - e[i].l + 1) - tmp; } } for(int i = 1; i <= q; i++) cout << ans[i] << '\n'; }}```:::
### C. 蜗蜗的魔力数字
暴力的写法就是数位DP板子,不需要太多解释😑。
由于我们直接跑数位DP它的状态是存不下的🤨,所以我们思考如何将他当前1的个数状态消除。我们观察他给我们递推式子👀,其实是可以直接将答案的整体通过这个式子进行求答案的😬,就可以把它的第二维舍去🤯。
但是不知道是记忆化搜索不是很好写还是傻逼错误导致我始终没有过大样例😤,下面是一种 `for` 循环的更好方法。
我们定义维度 $sum_{1,i,limit}$ 表示前 $i$ 个数,是否有约束的所有 $f(i-1)$ 的总值。
定义维度 $sum_{2,i,limit}$ 表示前 $i$ 个数,是否有约束的所有 $f(i-2)$ 的总值。
**对于有限制时的转移**:
所以便有:
$$sum_{1,i + 1,s_i=0} += sum_{1,i,1}$$
$$sum_{0,i + 1,s_i=0} += sum_{0,i,1}$$
当对于有限制的情况下当前位可以取到 $1$ 时
$$sum_{1,i + 1,s_i=1} += a \times sum_{1,i,1} + sum_{0,i,1}$$
$$sum_{0,i + 1,s_i=1} += sum_{1,i,1}$$
**对于没有限制时的转移**:
$$sum_{1,i+1,0} += sum_{1,i,0} + sum_{1,i,0} \times a + sum_{0,i,0}$$
$$sum_{1,i+1,0} += sum_{0,i,0} + sum_{1,i,0}$$
:::info[考场代码]```cpp#include<bits/stdc++.h>#define int long long
using namespace std;
const int MAXX = 1e7 + 5, M = 1e9 + 7;
string s;int n, sum[2][MAXX][2], a;
signed main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> s >> a; n = s.size(); s = ' ' + s; sum[1][1][1] = 1; for(int i = 1; i <= n; i++){ sum[1][i + 1][s[i] - '0' == 0] = (sum[1][i + 1][s[i] - '0' == 0] + sum[1][i][1]) % M; sum[0][i + 1][s[i] - '0' == 0] = (sum[0][i + 1][s[i] - '0' == 0] + sum[0][i][1]) % M; if(s[i] - '0' == 1){ sum[1][i + 1][s[i] - '0' == 1] = (sum[1][i + 1][s[i] - '0' == 1] + sum[1][i][1] * a + sum[0][i][1]) % M; sum[0][i + 1][s[i] - '0' == 1] = (sum[0][i + 1][s[i] - '0' == 1] + sum[1][i][1]) % M; } sum[1][i + 1][0] = (sum[1][i + 1][0] + (sum[1][i][0] + sum[1][i][0] * a % M + sum[0][i][0]) % M) % M; sum[0][i + 1][0] = (sum[0][i + 1][0] + (sum[0][i][0] + sum[1][i][0]) % M) % M; } cout << (sum[0][n + 1][0] + sum[0][n + 1][1]) % M; return 0;}```:::
### D. 蜗蜗的连线博弈
考试时来不及看了🙄
### E. Jump
考试时来不及看了🙄
## 整体反思
一句话评价:我是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 题都没调出来写个蛋啊😢!
## 整体反思
今天挂了本学期最多的一次挂分,也是荣誉再次拿下倒数了😨。
感觉自己的思维和对算法的运用能力还要加强😑。
自我感觉粗心错误以无药可救💀。