HDU多校联考记录

· · 个人记录

队伍配置

金牌爷yyc(command_block) 和 银牌爷yyn

Round 5(2023/8/1)

过了 11 题,有一道套路题没过,rk28。

赛时随机开题开到了比赛几乎最简单的 1007,很快地写了,但受限于没有拷计数板子,于是慢了一点。

然后开到了另一个签到题 1012,很快地签了个到。

yyn 开另一道签到题 1001,但由于计算几何板子不是很好,导致一直被卡精度和卡常。

我先去看了 $1005$,由于我是生成函数菜鸡,便用组合意义推了一下,发现可以用 [「MCOI-02」Build Battle 建筑大师](https://www.luogu.com.cn/problem/P6811) 的套路计算前缀和(其实和生成函数展开异曲同工)。 此时 yyn 终于把卡常的 $1001$ 过了,yyc 也过了 $1008$。 我先去开了 $1006$,yyc 去开了 $1003$ 和 $1004$,yyn 去开了 $1009$。 很快,捷报频传,我们都过了,转眼只剩下 $3$ 题了。 数学带师 yyc 去开了 $1002$,yyn 去做了 $1011$,我开 $1010$。 我 $1010$ 没想到子树外求两两异或最大值的套路,于是转去帮 yyn 开 $1011$。 yyn $1011$ 细节写挂了挺多,而且不知为什么用了 map 多带个 log。 于是我打算 $1011$ 自己写一遍,拷了 $LG$ 仙人掌板子,写完发现 WA 了,原来是 $LG$ 数据水,我板子写挂了,然后改了板子和 yyn 几乎同时过了 $1011$。 yyc 也把 $1002$ 过了,于是我想了个可能正确的做法怒冲 $1010$,被卡常,无果。 最后 $rk28$,其实挺满意的,主要 $1001$ 和 $1011$ 罚时太多了。 ## Round 6(2023/8/3) ![](https://cdn.luogu.com.cn/upload/image_hosting/h72cwyz2.png) yyn 很快就把 $1001$ 签到了,yyc 一开始就开到 $1011$ 本场比赛第二难的题。 我则随机开到了 $1006$,见没有人过,手快拿了一血。 yyn 接着继续把 $1002$ 过了,$yyc$ 放弃 $1011$ 去签了 $1010$。 我一看 $1004$ 是点分治板子,于是去拷了个板子很快地也写了。此时实时排名到了 $rk2$。 $yyc$ 去开了 $1008$,罚了几发罚时也过了。 我则去看了 $1005$,想到个 $nmlog$ 的做法,于是很快地写了,交上去 $T$ 了。 我仔细想了想发现 $log$ 可以去掉,于是很快地写了个 $O(nm)$ 的做法,结果发现用了 $scanf$ 没用快读,改了快读就过了。 此时,yyn 和 $1003$ 鏖战许久,yyc 也在做 $1007$。 留给我的只有 $1009$ 和 $1011$ 两道几乎没人过的题。 我看 $1011$ 是字符串题,$1009$ 感觉是网络流,于是我先开了 $1011$。 不久 $yyc$ 把 $1007$ 过了,并且狠狠踩了标算, $12s$ 的题跑了 $120ms$。 $yyn$ 把 $1003$ 也过了,现在只剩下了我的 $1011$ 和只有 $2$ 队过了的 $1009$。 我大概想到了 $1011$ 的做法,在距离比赛结束还有一个小时开始冲 $SAM+set$ 启发式合并。 大概距离比赛还有半个小时的时候写完,被卡常了。 于是将 $set$ 启发式合并改成了线段树合并。(键盘都敲冒烟了) $15min$ 之后,写完提交,发现过不了。不过 $10min$ 之后发现自己多测没清空,清空了就过了。 距离比赛还有 $6min$ 绝杀了 $1011$,赛时只有 $13$ 个队伍过的题。 最终排名 $rk6$ 且喜提 $1006$ 一血。 题解: ### 1011 题意: 给定一个模式串 $S$ 和 $q$ 个文本串 $T_i$,设 $S(l,r)$ 表示 $S$ 中 $l$ 到 $r$ 字符组成的子串, $f(S')=\sum_{l,r} [S' \in S(l,r)] $,其中 $S'\in S$ 表示 $S'$ 是 $S$ 的子串。 问你对于每个 $i$ ,求 $T_i(l,r)$ 的期望。($|S|\le10^5,\sum|T|\le10^6$) 首先对 $S$ 建立后缀自动机。 然后对于 $T$ 求所有前缀在 $S$ 中出现的最长后缀,设前缀 $T(1,j)$ 的最长后缀是 $T(i,j)$ ,那么 $T(i,j),T(i+1,j),\cdots,T(j,j)$ 都会有贡献且都是 $S$ 的子串,在 $S$ 的 $parent\;tree$ 上对应一条由根出发的链。 现在问题就变成了对于 $S$ $parent\;tree$ 上的节点,求出 $S$ 有多少个子串是包含它。 设这个节点表示的子串为 $S'$,考虑它的 $endpos$ 集合,一个子串 $S''$ 合法当且仅当它包住了至少一个完整的在原串 $S$ 中的 $S'$。 考虑计数,对于每个 $S''$,只在它包住第一个 $S'$ 时统计,设相邻的两个 $endpos$ 为 $i,j$,考虑第一个包住的是 $(j-|S'|+1,j)$,那么左端点可以取 $[i-|S'|+1,j-|S'|+1]$,右端点可以取 $[j,|S|]$,方案数为 $(j-i)\times(|S|-j+1)$。 特别地,若 $i$ 是第一个 $endpos$,方案数为 $(i-|S'|+1)\times(|S|-i+1)$。 容易发现它们的和是一个关于 $|S'|$ 的一次函数。 细节:$T$ 匹配到的可能是 $S$ 后缀自动机上一个节点的一部分前缀,维护匹配的长度即可。 用线段树合并维护 $endpos$ 集合即可,时间复杂度 $O(|S|log|S|+\sum|T|)$。 ```c++ #pragma GCC optimize(3,"Ofast","inline") #include<bits/stdc++.h> using namespace std; const int mo=998244353; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } //快写 inline void write(int x) { if(x<0) { putchar('-'); x = -x; } if(x>9) write(x / 10); putchar(x % 10 + '0'); } int n; char s[1000005]; int fast_pow(int a,int p){ int sum=1; while(p){ if(p&1)sum=1ll*sum*a%mo; a=1ll*a*a%mo; p>>=1; } return sum; } int add(int u,int v){ return (u+v>=mo?u+v-mo:u+v); } int now; struct SAM{ int last; int son[26]; int siz; }t[200005]; int g; void Insert(int u,int c){ int v=++g; for(int i=0;i<26;i++)t[v].son[i]=0; t[v].siz=t[u].siz+1; now=v; int p=u; while(p!=-1 && !t[p].son[c]){ t[p].son[c]=v; p=t[p].last; } if(p==-1)t[v].last=0; else { int q=t[p].son[c]; if(t[p].siz+1==t[q].siz){ t[v].last=q; } else { int copy=++g; t[copy].siz=t[p].siz+1; for(int i=0;i<26;i++)t[copy].son[i]=t[q].son[i]; t[copy].last=t[q].last; while(p!=-1 && t[p].son[c]==q){ t[p].son[c]=copy; p=t[p].last; } t[q].last=t[v].last=copy; } } } vector<int>nxet[200005]; bool pd[200005]; set<int>st[200005]; int k[200005],b[200005]; int sum[200005]; struct Seg{ int lson,rson; int k,b; int L,R; }tt[8000005]; int tnt; int root[200005]; void update(int rt){ if(!tt[tt[rt].rson].R){ tt[rt].k=tt[tt[rt].lson].k; tt[rt].b=tt[tt[rt].lson].b; tt[rt].L=tt[tt[rt].lson].L; tt[rt].R=tt[tt[rt].lson].R; } else if(!tt[tt[rt].lson].R){ tt[rt].k=tt[tt[rt].rson].k; tt[rt].b=tt[tt[rt].rson].b; tt[rt].L=tt[tt[rt].rson].L; tt[rt].R=tt[tt[rt].rson].R; } else { tt[rt].L=tt[tt[rt].lson].L; tt[rt].R=tt[tt[rt].rson].R; tt[rt].k=tt[tt[rt].lson].k; tt[rt].b=add(tt[tt[rt].lson].b,tt[tt[rt].rson].b); int x=tt[tt[rt].lson].R,y=tt[tt[rt].rson].L; tt[rt].b=add(tt[rt].b,mo-1ll*(n-y+1)*(y+1)%mo); tt[rt].b=add(tt[rt].b,1ll*(n-y+1)*(y-x)%mo); } // cout << } void ins(int l,int r,int d,int &rt){ if(!rt){ rt=++tnt; tt[rt].lson=tt[rt].rson=tt[rt].L=tt[rt].R=tt[rt].k=tt[rt].b=0; // return; } if(l==r){ tt[rt].L=tt[rt].R=d; tt[rt].k=mo-(n-d+1);tt[rt].b=1ll*(d+1)*(n-d+1)%mo; return; } int mid=l+r>>1; if(mid>=d)ins(l,mid,d,tt[rt].lson); if(mid<d)ins(mid+1,r,d,tt[rt].rson); update(rt); } void merge(int l,int r,int &rt,int lrt){ if(!rt||!lrt){ rt=rt+lrt; return; } if(l==r)return; int mid=l+r>>1; merge(l,mid,tt[rt].lson,tt[lrt].lson); merge(mid+1,r,tt[rt].rson,tt[lrt].rson); update(rt); } void calc2(int u){ // cout << u<<endl; for(int i=0;i<nxet[u].size();i++){ int v=nxet[u][i]; calc2(v); merge(1,n,root[u],root[v]); // sum[u]=add(sum[u],sum[v]); } k[u]=tt[root[u]].k,b[u]=tt[root[u]].b; // cout << u <<" "<< k[u]<< ' '<< b[u]<<endl; if(u)sum[u]=add(add(sum[u],1ll*b[u]%mo*1ll*(t[u].siz-t[t[u].last].siz)%mo),1ll*k[u]%mo*1ll*(1ll*(t[u].siz+t[t[u].last].siz+1)*(t[u].siz-t[t[u].last].siz)/2%mo)%mo); // cout << u<<" "<<sum[u]<<endl; } void calc3(int u){ for(int i=0;i<nxet[u].size();i++){ int v=nxet[u][i]; sum[v]=add(sum[u],sum[v]); calc3(v); } } int main(){ int T; scanf("%d",&T); while(T--){ int q; // scanf("%d%d",&n,&q); n=read();q=read(); // n=100000,q=1; scanf("%s",s+1); // for(int i=1;i<=n;i++)s[i]=(rand()&1)?'a':'b'; t[0].last=-1; for(int i=0;i<26;i++)t[0].son[i]=0; now=0;g=0; tnt=0; for(int i=1;i<=n;i++){ Insert(now,s[i]-'a'); ins(1,n,i,root[now]); } for(int i=1;i<=g;i++)nxet[t[i].last].push_back(i); calc2(0); sum[0]=0; calc3(0); for(int i=1;i<=q;i++){ scanf("%s",s+1); // int nn=1000000; // for(int j=1;j<=nn;j++)s[i]=(rand()&1)?'a':'b'; int u=0;int lim=strlen(s+1); int len=0;int ans=0; for(int j=1;j<=lim;j++){ int c=s[j]-'a'; while(u&&!t[u].son[c])u=t[u].last,len=t[u].siz; if(t[u].son[c])u=t[u].son[c],len++; // cout << u<<" "<< k[u] <<" "<< b[u] <<endl; if(u){ans=add(ans,sum[t[u].last]);ans=add(add(ans,b[u]*1ll*(len-t[t[u].last].siz)%mo),k[u]*1ll*(1ll*(len+t[t[u].last].siz+1)*(len-t[t[u].last].siz)/2%mo)%mo);} // cout << ans << " " << add(add(0,1ll*b[u]%mo*1ll*(len-t[t[u].last].siz)%mo),1ll*k[u]%mo*1ll*(1ll*(len+t[t[u].last].siz+1)*(len-t[t[u].last].siz)/2%mo)%mo)<<endl; } // cout << ans<<endl; write(1ll*ans*fast_pow(1ll*(lim+1)*lim/2%mo,mo-2)%mo); putchar('\n'); // printf("%d\n",); } for(int i=0;i<=g;i++)nxet[i].clear(),root[i]=0,k[i]=b[i]=sum[i]=0; } return 0; } ``` ## Round 7(2023/8/8) ![](https://cdn.luogu.com.cn/upload/image_hosting/7vy2ljfc.png) 开局 lianggj 把机房门锁住了,导致迟了 $15$ 分钟才开始比赛,打开电脑时 yyc 已经把 $1011$ 切了。 yyn 先去写了 $1002$,yyc 继续去写了 $1011$。 剩下的题此时都没人过,我先去看了 $1004$ ,发现是个构造题,想了一会感觉结论不会太简单(当时 $0/40$ 带给我的自信)。 我想了一会感觉有点想法,不知道对不对,但是看了 $1005$ 发现是个字符串题,感觉是 $SAM+\text{子序列自动机}$ 板子题 ,于是先去做了 $1005$。 此时 $1002$ 和 $1011$ 都被切了,yyn 去开了 $1006$,yyc 去开了 $1012$。 我写完 $1005$ 后,再把 $1004$ 的结论一交,发现一发过了。 然后去写 $1008$ 这个经典题,很快也过了,yyc 也过了 $1012$,此时 $SMZX$ 榜上 $rk1$。 然后我去做 $1010$,一看名字 $\text{Widely Known Problem}$ ,我去,这不是[[候选队互测]广为人知题](https://uoj.ac/problem/697) 吗,发现题目略有不同,不会,直接开摆(最后也没人过)。 后冲 $1006$,yyc 冲 $1001$ 无果,遗憾离场。 赛后,一看题解,$1010$ 果然是基本子串结构,$\text{std}$ 长达 $10k$,代码第一行 $\text{xtqqwq}$,太酷啦! ## Round 8(2023/8/10) ![](https://cdn.luogu.com.cn/upload/image_hosting/u7by6437.png) 今天打得不是很好,且题目做的没什么含金量,不说了