版本比较
【YFOI-A2026】2026 年扬帆愚人节比赛 赛后总结帖 & 题解
正文
增加 218 行删除 1 行
12 行未改动13141516171718192021493 行未改动全部展开5155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387392,937 行未改动全部展开12 行未改动## 脑操
idea:很多人。
solution:[chengyifan91](https://www.luogu.com.cn/user/1512824)。solution & checker:[chengyifan91](https://www.luogu.com.cn/user/1512824)。
本题在很久之前就被出出来了,chengyifan91 感觉非常愚人节,就放到比赛里了。
:::info[简述题意]493 行未改动全部展开:::
::::
:::error[checker]```cpp#include "testlib.h"#include<bits/stdc++.h>using namespace std;
int tp, p=5e5+5, cnt, inp, oup, anp, spj;string s;const int N = 1e6 + 10;int in[N], out[N], an[N], a[N], st[N], nxt[N], lst[N];vector<int> g[N];
#define gi(l, r) (rnd()%(int(r)-int(l)+1)+int(l))
void run(int l, int r) { for (int i = l; i <= r; i++) { if (s[i] == '+') ++cnt, ++a[p]; else if (s[i] == '-') ++cnt, --a[p]; else if (s[i] == '<') ++cnt, --p; else if (s[i] == '>') ++cnt, ++p; else if (s[i] == ',') { ++inp; ++cnt; a[p] = in[inp]; if (inp > 1e6) return ; } else if (s[i] == '.') { ++oup; ++cnt; out[oup] = a[p]; if (oup > 1e6) return ; } else if (s[i] == '[') { ++cnt; if (!a[p]) i = nxt[i], --cnt; } else if (s[i] == ']') i = lst[i]-1; if (cnt > 1e7) return ; if (abs(p-500000-5) > 3e5) return ; }}
bool isop(char c) { return c == '+' || c == '-' || c == '<' || c == '>' || c == ',' || c == '.' || c == '[' || c == ']';}
int read(int x) { in[++inp] = x; return x;}
int write(int x) { an[++anp] = x; return x;}
void solve(int id, mt19937 &rnd, int t) { if (id == 1) read((t&1)*gi(4e5, 5e5)), write(!in[inp]); if (id == 2) read(gi(9e4, 1e5)), write(in[inp]), read(gi(9e4, 1e5)), an[anp] += in[inp]; if (id == 3) read(gi(9e4, 1e5)), write(in[inp]), read(gi(5e4, in[inp])), an[anp] -= in[inp]; if (id == 4) read(gi(200, 300)), write(in[inp]), read(gi(200, 300)), an[anp] *= in[inp]; if (id == 5) read(gi(90, 100)), write(in[inp]), read((t<=2)?t:gi(20, 30)), an[anp] /= in[inp]; if (id == 6) read(gi(90, 100)), write(in[inp]), read((t<=2)?t:gi(20, 30)), an[anp] %= in[inp]; if (id == 7) { int n = read(gi(400, 500)), k = gi(400, n); for (int i = 1; i <= n; i++) read(gi(0, 1)*gi(9e8, 1e9)), (i <= k ? write(in[inp]) : 0); read(k); } if (id == 8) { int n = read(gi(200, 300)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { write(i == j ? read(gi(9e8, 1e9)), 0 : read(gi(9e8, 1e9))); } } } if (id == 9) { int n = 140, mn = 140, mx = 0; read(n); for (int i = 1; i <= n; i++) mn = min(mn, read(gi(1, 140))), mx = max(mx, in[inp]); write(mx); write(mn); } if (id == 10) { int n = read(gi(240, 250)), ans = 0; for (int i = 1; i <= n; i++) if (n % i == 0) ans++; write(ans); } if (id == 11) { int v = gi(40, 50); int n = read(v), k = gi(v-10, n), ans = 0; for (int i = 1; i <= n; i++) ans += (i <= k ? read(gi(v-10, v)) : (read(gi(v-10, v)), 0)); read(k); write(ans-114514); } if (id == 12) { int v = 50; int n = read(gi(v-10, v)), q = read(gi(v-10, v)); for (int i = 1; i <= n; i++) a[i] = read(gi(9e8, 1e9)); while (q--) { int l = read(gi(1, sqrt(n))), r = read(gi(n-sqrt(n), n)); for (int i = l; i <= r; i++) ++a[i]; } for (int i = 1; i <= n; i++) write(a[i]), a[i] = 0; } if (id == 13) { int n = read(gi(200, 300)), ans = 1; for (int i = 1; i <= n; i++) a[i] = read(gi(0, 1)||i==1?gi(1, 300):a[i-1]); for (int i = 1; i < n; i++) ans += (a[i] != a[i+1]); write(ans); for (int i = 1; i <= n; i++) a[i] = 0; } if (id == 14) { int n = read(gi(30, 60)), ans = 0; for (int i = 1; i <= n; i++) a[read(gi(1, 30))]++, ans += (a[in[inp]] == 1); write(ans); for (int i = 1; i <= 30; i++) a[i] = 0; } if (id == 15) { int n = read(gi(50, 60)); for (int i = 1; i <= n; i++) a[i] = read(gi(1, 50)); sort(a+1, a+n+1); for (int i = 1; i <= n; i++) write(a[i]), a[i] = 0; } if (id == 16) { int n = read(gi(90, 100)); for (int i = 1; i <= n; i++) a[read(gi(1, n/2))]++; for (int i = 1; i <= n; i++) { if (!a[i]) { write(i); break; } } for (int i = 0; i <= 100; i++) a[i] = 0; } if (id == 17) { int n = read(70); read(0); for (int i = 2; i <= n; i++) a[i] = read(gi(max(1, i-5), i-1)); int u = read(gi(1, n-1)), v = read(n), tu = u, tv = v; while (u != v) { if (!a[u]) u = tv; else u = a[u]; if (!a[v]) v = tu; else v = a[v]; } write(u); for (int i = 2; i <= n; i++) a[i] = 0; }}
int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); while (!ouf.eof()) s += ouf.readLine(); if (s.size() > 1024) { quitf(_wa, "CE (Changdu Error)"); return 0; } s.erase(remove_if(s.begin(), s.end(), [](char c){return !isop(c);}), s.end()); for (int i = 0; i < (int)s.size(); i++) { if (s[i] == '[') st[++tp] = i; if (s[i] == ']') { if (!tp) { quitf(_wa, "CE (Compile Error)"); return 0; } lst[i] = st[tp]; nxt[st[tp--]] = i; } } if (tp) { quitf(_wa, "CE (Compile Error)"); return 0; } int ce = 0, wa = 0, mxcnt = 0, oknum = 0; for (int id = 1; id <= 5; id++) { mt19937 rnd(((t<<3)^id)+114514-6578+11738-11831+3920-4848+12423+7891-1391-1378); inp = oup = anp = cnt = 0; p = 5e5+5; for (int j = 1; j <= 1e6; j++) in[j] = -1, a[j] = an[j] = out[j] = 0; solve(t, rnd, id); inp = 0; run(0, s.size()-1); mxcnt = max(mxcnt, cnt); if (cnt > 3e6) { if (ce != 1) ce = 4; if (!ce) ce = 1; continue; } if (abs(p-500000-5) > 3e5) { if (ce != 2) ce = 4; if (!ce) ce = 2; continue; } if (oup > 1e6 || inp > 1e6) { if (ce != 3) ce = 4; if (!ce) ce = 3; continue; } if (anp != oup) { wa = 1; continue; } for (int i = 1; i <= anp; i++) { if (an[i] != out[i]) { wa = 1; --oknum; break; } } ++oknum; } if (ce == 1) quitp(oknum*0.2, "CE (Coin Error: %d)", mxcnt); if (ce == 2) quitp(oknum*0.2, "CE (Chaju Error)"); if (ce == 3) quitp(oknum*0.2, "CE (Cishu Error)"); if (ce == 4) quitp(oknum*0.2, "CE (C??? Error)"); if (wa == 1) quitp(oknum*0.2, "WA (Wrong Answer)"); quitf(_ok, "AC (All Cao) Coin: %d Length: %d", mxcnt, (int)s.size()); return 0;}```:::
## 树从树变成了图然后求最大值问题
idea & solution & grader:[chengyifan91](https://www.luogu.com.cn/user/1512824)。
2,937 行未改动全部展开