版本比较
你群の海灯节欢乐赛 2026 题解
正文
增加 88 行删除 35 行
24 行未改动2526272829303132333459 行未改动949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152116 行未改动全部展开26927027127222027327427527627719 行未改动2972982993002483013023033043054 行未改动3103113123132613143153163173184 行未改动3233243253262743273283293303313 行未改动33533633733828633934034134234315 行未改动35936036136231036336436536636717 行未改动38538638738833638939039139239323 行未改动417418419420368421422423424425373426427428429430431432433381434435436437438210 行未改动全部展开6496506516526006536546556566573 行未改动66166266366461266566666766866922 行未改动6926936946956436446456966976986997007016497027037047057064 行未改动71171271371466271571666471771871972072166972272372472572672772872967773073167973273373473573687 行未改动8248258268277758288297778308318328338343 行未改动838839840841789790791792793842843844845846847795848849797798799850851852853854802855856857858859125 行未改动全部展开985986987988936989990991992993301 行未改动全部展开1295129612971298124612991300130113021303293 行未改动全部展开24 行未改动没有特殊说明的,题解一律来自“出题”一栏的选手。
# A / Q
## 做法一
> Solution by @[JuRuoOIer](https://www.luogu.com.cn/user/476093)
考虑将 $b$ 分解质因数,显然 $200$ 以内除 $2^7=128,3^4=81,5^3=125,7^2=49,11^2=121,13^2=169$ 外所有质数的指数最大为 $1$。于是将 $128,81,125,49,121,169$ 及所有 $[17,200]$ 间的质数分成若干段,每段内相乘的结果不超出 `int`,然后每段乘起来压成一个 `int`,读入的过程中就只需要对这若干个 `int` 取模即可。
59 行未改动}
```
## 做法二
> Solution by @[cAncAn998244353](https://www.luogu.com.cn/user/448885)
通过 `fseek` 函数实现先读入 `b` 后读入 `a`。
```cpp#include <bits/stdc++.h>using namespace std;//#define getc getcharchar buf[1<<21],*p1=buf,*p2=buf;#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)inline long long read(){ char c = getc() , f = 1; while (c > '9' || c < '0'){ if (c == '-')f = -1; c = getc(); } long long p = 0; while (c >= '0' && c <= '9'){ p = p * 10 + c - '0'; c = getc(); } return p * f;}char s[30000005];int x[2005];signed main(){ int mod = 0; char c = getc(); while (c != ' ')c = getc(); c = getc(); while (c >= '0' && c <= '9'){ mod = mod * 10 + c - '0'; c = getc(); } for (int i = 1;i < 10 * mod;++i){ x[i] = i % mod; } fseek(stdin,0,SEEK_SET); int ans = 0; c = getc(); while (c != ' '){ ans = x[ans * 10 + c - '0']; c = getc(); } printf ("%d" , ans); return 0;}```
# B
直接模拟即可,任何国外的模型应该都能写出 std。由于出题人编写的 std 有锅,此处随便找了一个选手代码。
116 行未改动全部展开 tot[atoid[name]]+=nm*mul; // cerr<<"NAME{"<<name<<"}nm{"<<nm<<"}mul{"<<mul<<"}\n"; nm=1; len=0; } } } if(sta.size()) return 0; if(len) return 0; valcnt++;19 行未改动 ios::sync_with_stdio(0),cin.tie(nullptr); // freopen("chemistry3.in","r",stdin); // freopen("chemistry.out","w",stdout); rep(i,0,K) atomass[S[i]]=M[i]; rep(i,0,K) atoid[S[i]]=i; rep(i,0,K) atoid[S[i]]=i; int op; int q=0; for(;;){ cin>>op;4 行未改动 string s; cin>>s; s=" "+s; SQ[q][0]=s; bool t1=calcmass(s); bool t1=calcmass(s); } if(op==2){ int d; string s;4 行未改动 s=" "+s; SQ[q][0]=s; } if(d==1){ cin>>d; cin>>d; CN[q]=d; rep(i,0,d-1){ cin>>SQ[q][i]; // SQ[q][i].insert(beg(SQ[q][i]),' ');3 行未改动 } } if(op==3){ int d; cin>>d; cin>>d; CN[q]=d; OP[q]=4; rep(i,0,d-1){ cin>>SQ[q][i];15 行未改动 // int res=0; // for(auto[x,y]:val[i].ele) res+=M[x]*y,cerr<<"{"<<S[x]<<","<<y<<"} "; // debug(res); // cerr<<"\n";
// } fill(tot,tot+120,0); int as=0; rep(i,1,q){17 行未改动 } vis[id]=1; cout<<"="; int d=commass[SQ[i][0]]; // if(d%10) // if(d%10) cout<<d/10<<"."<<d%10<<".\n"; // else cout<<d/10<<".\n"; } }else{23 行未改动 int cbt; int p=0; int d=CN[i]; rep(j,0,d-1){
if(!atoid.count(SQ[i][j])){ cout<<"Invalid.\n"; goto ed; } tid[j]=atoid[SQ[i][j]]; tid[j]=atoid[SQ[i][j]]; } sort(allt(tid,0,d)); if(d==1){ Bt=B2[tid[0]][tid[0]]; }else if(d==2){ Bt=B2[tid[0]][tid[1]]; }else if(d==3){ Bt=B2[tid[0]][tid[1]]&B2[tid[2]][tid[2]]; Bt=B2[tid[0]][tid[1]]&B2[tid[2]][tid[2]]; }else if(d==4){ Bt=B2[tid[0]][tid[1]]&B2[tid[2]][tid[3]]; }else{ Bt=B2[tid[0]][tid[1]]&B2[tid[2]][tid[3]]&B2[tid[4]][tid[4]];210 行未改动全部展开 for(int i=1;i<=n;i++){ int x=ask(a[i]); add(a[i]+1,-1); a[i]=x; } } memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) add(i,1); for(int i=1;i<=n;i++){ int x=ask(b[i]);3 行未改动 for(int i=n;i>=1;i--){ int mod=n-i+1; t[i]+=a[i]+b[i]; if(i!=1) t[i-1]+=t[i]/mod; t[i]%=mod; t[i]%=mod; } memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) add(i,1); for(int i=1;i<=n;i++){22 行未改动ll n,vis[2010],v[2010],dis[2010],ans,flg,mx;ll u;vector<ll> a[2010];void work(ll now){ mx=0;//当前连通块内的答案 memset(v,0,sizeof(v));//记录本连通块内的点集 vis[now]=1;//1/2染色方案 0表示没染 mx=0;//当前连通块内的答案 memset(v,0,sizeof(v));//记录本连通块内的点集 vis[now]=1;//1/2染色方案 0表示没染 v[now]=1; queue<ll> q; q.push(now); while(!q.empty()){//BFS 进行染色 while(!q.empty()){//BFS 进行染色 ll tmp=q.front(); q.pop(); for(int i=0;i<a[tmp].size();i++){ if(!vis[a[tmp][i]]){4 行未改动 else if(vis[a[tmp][i]]==vis[tmp]){ flg=1; return ; } } } } for(int i=1;i<=n;i++){//枚举每个点 for(int i=1;i<=n;i++){//枚举每个点 if(!v[i])continue; memset(dis,0,sizeof(dis)); dis[i]=1; q.push(i); while(!q.empty()){//BFS 求到各点的距离 while(!q.empty()){//BFS 求到各点的距离 ll tmp=q.front(); q.pop(); for(int i=0;i<a[tmp].size();i++){ if(!dis[a[tmp][i]]){ dis[a[tmp][i]]=dis[tmp]+1; q.push(a[tmp][i]); } } } } for(int j=1;j<=n;j++){//求最大值 for(int j=1;j<=n;j++){//求最大值 mx=max(mx,dis[j]); } } ans+=mx;87 行未改动 s+=a; s%=k-1; } if(s)cout<<"No"; else cout<<"Yes"; else cout<<"Yes"; cout<<endl; } } return 0;}
```3 行未改动树剖换根 + 势能线段树。
## 核心思路### 1. 线段树势能分析对于 区间取模 和 区间开方,显然难以维护 Lazy Tag。但利用两个数学性质(证明略):$\sqrt{x}$ 收敛极快,一般只需要 $6$ 次开方即可收敛至1。$x \bmod p < x/2$ (当 $p < x$)。 因此我们可以使用如下方式来剪枝: 维护区间最大值 max_val。 - 若 max_val < p (取模) 或 max_val <= 1 (开方),操作对该区间无意义,直接 Return。 - 否则,暴力递归到叶子修改。 对于 区间取模 和 区间开方,显然难以维护 Lazy Tag。但利用两个数学性质(证明略):$\sqrt{x}$ 收敛极快,一般只需要 $6$ 次开方即可收敛至1。$x \bmod p < x/2$ (当 $p < x$)。因此我们可以使用如下方式来剪枝:维护区间最大值 max_val。- 若 max_val < p (取模) 或 max_val <= 1 (开方),操作对该区间无意义,直接 Return。- 否则,暴力递归到叶子修改。
势能分析证明复杂度均摊为 $O(m \log n \log (\text{Val}))$。($Val$为总值) 势能分析证明复杂度均摊为 $O(m \log n \log (\text{Val}))$。($Val$为总值)### 2. 换根操作不需要LCT,只需假定 $1$ 为根建树剖,维护一个逻辑根 rt。设当前查询节点 $u$,分类讨论: 1,$u = rt$:操作 全树。 2,$u$ 不是 $rt$ 的祖先:$rt$ 不在 $u$ 的子树内,操作 $u$ 的物理子树。 不需要LCT,只需假定 $1$ 为根建树剖,维护一个逻辑根 rt。设当前查询节点 $u$,分类讨论:1,$u = rt$:操作 全树。2,$u$ 不是 $rt$ 的祖先:$rt$ 不在 $u$ 的子树内,操作 $u$ 的物理子树。3,$u$ 是 $rt$ 的祖先:$rt$ 在 $u$ 的子树内。- 找到 $u \to rt$ 路径上紧贴 $u$ 的那个直系儿子 $v$。- 操作范围 = 全树 挖掉 $v$ 的物理子树。 - 操作范围 = 全树 挖掉 $v$ 的物理子树。## AC 代码```#include<bits/stdc++.h>using namespace std;125 行未改动全部展开 return; }
int lca = get_lca(u, root_now);
if (lca == u) { int v = find_child(u, root_now); if (type == 1) { if (dfn[v] > 1) modify_sqrt(1, 1, n, 1, dfn[v] - 1);301 行未改动全部展开 for(int i=0;i<n;i++){ cout<<a[s[i]]<<endl; } return 0;} }```
# K
293 行未改动全部展开