当前位置: 首页 > news >正文

晋城住房保障和城乡建设管网站百度收录哪些平台比较好

晋城住房保障和城乡建设管网站,百度收录哪些平台比较好,杭州微网站,明星网页制作模板字符串题 题目链接:YBT2023寒假Day14 C 题目大意 对于一个字符串 S 定义 F(S) 是 fail 树上除了 0 点其它点的深度和。 G(S) 是 S 每个子串 S’ 的 F(S’) 之和。 然后一个空串,每次在后面加一个字符,要你维护这个串的 G 值。 思路 考虑…

字符串题

题目链接:YBT2023寒假Day14 C

题目大意

对于一个字符串 S 定义 F(S) 是 fail 树上除了 0 点其它点的深度和。
G(S) 是 S 每个子串 S’ 的 F(S’) 之和。
然后一个空串,每次在后面加一个字符,要你维护这个串的 G 值。

思路

考虑把 G(S[1,x])G(S[1,x])G(S[1,x]) 值差分一下,会发现 G(S[1,i])−G(S[1,i−1])G(S[1,i])-G(S[1,i-1])G(S[1,i])G(S[1,i1]) 的值其实是以 iii 为结尾的子串的 FFF 值之和。
那从子串变成了一个后缀,看起来就可做很多了,考虑怎么算。

那我们看 fail 树性质,一个字符串 SSSjjjiii 的祖先当且仅当 S[1,j]=S[i−j+1,i]S[1,j]=S[i-j+1,i]S[1,j]=S[ij+1,i]
F(S)F(S)F(S) 就是满足 S[1,j]=S[i−j+1]S[1,j]=S[i-j+1]S[1,j]=S[ij+1]1⩽j<i1\leqslant j<i1j<i(i,j)(i,j)(i,j) 对数。
那也就是在 SSS 里面选一个前缀,再选一个非前缀,它们相等的方案数。

注意到我们要求的是以 iii 结尾的 FFF 值之和,那开头就不固定,结尾是固定的。
FFF 值是选一个前缀,再一个非前缀,那这个是开头固定,结尾不固定。
那你这个开头固定放在开头不固定里,它不固定了,你这个结尾不固定在结尾固定里面肯定也是不固定。
所以头尾都不固定,只需要两个不是同一个位置的字符串相等即可。
那答案就是所有本质不同的子串的出现次数 xxx(x2)\binom{x}{2}(2x) 之和。


那注意到不需要在线,我们可以先建出最后的后缀树。
那我们用一个 dxd_xdx 表示每个点 xxx 对于子串的出现次数。
那插入就是把它到祖先路径的 dxd_xdx 加一,询问就是所有点的 endpos 大小乘 (dx2)\binom{d_x}{2}(2dx)
那这个维护这个和不难,我们记录着这个和 sumsumsum,每次要插入的时候,每个新贡献的值就是它 endpos 集合大小乘上 dxd_xdx(这个 dxd_xdx 还没加 111),然后你再把 dxd_xdx 加一。
那这个是路径加值,路径求和,直接树链剖分线段树维护即可。
复杂度 O(nlog⁡2n)O(n\log ^2n)O(nlog2n)


ex:
如果强制在线,我们也可以用 LCT 来维护这棵树,那就也是同样的操作,复杂度 O(nlog⁡n)O(n\log n)O(nlogn)

代码

#include<cstdio>
#include<vector>
#define ll long long
#define mo 1000000007using namespace std;const ll N = 4e5 + 100;
ll n, fa[N], sz[N], son[N], dfn[N], top[N], dy[N];
ll lst = 1, tot = 1, pla[N]; 
char s[N];struct node {ll son[26], len, fa;
}d[N];struct XD_tree {ll num[N << 2], f[N << 2], lzy[N << 2];void up(ll now) {num[now] = (num[now << 1] + num[now << 1 | 1]) % mo;f[now] = (f[now << 1] + f[now << 1 | 1]) % mo;}void downa(ll now, ll x) {(f[now] += x * num[now] % mo) %= mo;(lzy[now] += x) %= mo;}void down(ll now) {if (lzy[now]) {downa(now << 1, lzy[now]); downa(now << 1 | 1, lzy[now]);lzy[now] = 0;}}void build(ll now, ll l, ll r) {if (l == r) {num[now] = d[dy[l]].len - d[d[dy[l]].fa].len;return ;}ll mid = (l + r) >> 1;build(now << 1, l, mid); build(now << 1 | 1, mid + 1, r);up(now);}void update(ll now, ll l, ll r, ll L, ll R, ll x) {if (L <= l && r <= R) {downa(now, x); return ;}ll mid = (l + r) >> 1; down(now);if (L <= mid) update(now << 1, l, mid, L, R, x);if (mid < R) update(now << 1 | 1, mid + 1, r, L, R, x);up(now);}ll query(ll now, ll l, ll r, ll L, ll R) {if (L <= l && r <= R) return f[now];ll mid = (l + r) >> 1; down(now); ll re = 0;if (L <= mid) (re += query(now << 1, l, mid, L, R)) %= mo;if (mid < R) (re += query(now << 1 | 1, mid + 1, r, L, R)) %= mo;return re;}
}T;struct SLPF {vector <ll> G[N];void add(ll x, ll y) {G[x].push_back(y);}void dfs0(ll now, ll father) {fa[now] = father; sz[now] = 1;for (ll i = 0; i < G[now].size(); i++) {ll x = G[now][i];dfs0(x, now); sz[now] += sz[x];if (sz[x] > sz[son[now]]) son[now] = x;}}void dfs1(ll now, ll father) {dfn[now] = ++dfn[0]; dy[dfn[0]] = now;if (son[now]) {top[son[now]] = top[now]; dfs1(son[now], now);}for (ll i = 0; i < G[now].size(); i++) {ll x = G[now][i]; if (x == son[now]) continue;top[x] = x; dfs1(x, now);}}void build() {dfs0(1, 0); top[1] = 1; dfs1(1, 0);T.build(1, 1, tot);}void update_root(ll now) {while (now) {T.update(1, 1, tot, dfn[top[now]], dfn[now], 1);now = fa[top[now]];}}ll query_root(ll now) {ll re = 0;while (now) {(re += T.query(1, 1, tot, dfn[top[now]], dfn[now])) %= mo;now = fa[top[now]];}return re;}
}P;struct SAM {ll insert(ll x) {ll p = lst, np = ++tot; lst = np;d[np].len = d[p].len + 1;for (; p && !d[p].son[x]; p = d[p].fa) d[p].son[x] = np;if (!p) d[np].fa = 1;else {ll q = d[p].son[x];if (d[q].len == d[p].len + 1) d[np].fa = q;else {ll nq = ++tot; d[nq] = d[q];d[nq].len = d[p].len + 1;d[q].fa = d[np].fa = nq;for (; p && d[p].son[x] == q; p = d[p].fa) d[p].son[x] = nq;}}return np;}void build() {for (ll i = 2; i <= tot; i++) P.add(d[i].fa, i);}
}S;int main() {freopen("string.in", "r", stdin);freopen("string.out", "w", stdout);scanf("%lld", &n);scanf("%s", s + 1);for (ll i = 1; i <= n; i++) pla[i] = S.insert(s[i] - 'a');S.build(); P.build();ll sum = 0, ans = 0;for (ll i = 1; i <= n; i++) {(sum += P.query_root(pla[i])) %= mo;P.update_root(pla[i]);(ans += sum) %= mo;printf("%lld\n", ans);}return 0;
}

文章转载自:
http://malaceous.c7507.cn
http://crofting.c7507.cn
http://sourdine.c7507.cn
http://fou.c7507.cn
http://heckler.c7507.cn
http://cornel.c7507.cn
http://frameable.c7507.cn
http://novachord.c7507.cn
http://aplite.c7507.cn
http://prevenient.c7507.cn
http://amchitka.c7507.cn
http://fairily.c7507.cn
http://togavirus.c7507.cn
http://iron.c7507.cn
http://tetrapetalous.c7507.cn
http://disforest.c7507.cn
http://trimester.c7507.cn
http://kegling.c7507.cn
http://extraliterary.c7507.cn
http://lindy.c7507.cn
http://earlap.c7507.cn
http://leaderless.c7507.cn
http://indiscernibility.c7507.cn
http://schizocarp.c7507.cn
http://trouse.c7507.cn
http://kluck.c7507.cn
http://reside.c7507.cn
http://involving.c7507.cn
http://headcheese.c7507.cn
http://telephonic.c7507.cn
http://termwise.c7507.cn
http://toadflax.c7507.cn
http://giddiness.c7507.cn
http://chowderhead.c7507.cn
http://fist.c7507.cn
http://mojave.c7507.cn
http://stadium.c7507.cn
http://necrology.c7507.cn
http://barney.c7507.cn
http://anisomerous.c7507.cn
http://caltech.c7507.cn
http://jura.c7507.cn
http://handle.c7507.cn
http://troth.c7507.cn
http://cusp.c7507.cn
http://springlet.c7507.cn
http://agedness.c7507.cn
http://implication.c7507.cn
http://gustily.c7507.cn
http://jellied.c7507.cn
http://languishing.c7507.cn
http://worldliness.c7507.cn
http://selenite.c7507.cn
http://consols.c7507.cn
http://sala.c7507.cn
http://syrphid.c7507.cn
http://polyphage.c7507.cn
http://sepiolite.c7507.cn
http://jealously.c7507.cn
http://campus.c7507.cn
http://omphale.c7507.cn
http://international.c7507.cn
http://manuka.c7507.cn
http://cannily.c7507.cn
http://uniatism.c7507.cn
http://germinator.c7507.cn
http://accidented.c7507.cn
http://request.c7507.cn
http://cineangiocardiography.c7507.cn
http://reliever.c7507.cn
http://annaba.c7507.cn
http://sclerogenous.c7507.cn
http://photoconductive.c7507.cn
http://travancore.c7507.cn
http://shaba.c7507.cn
http://strutter.c7507.cn
http://sulphurwort.c7507.cn
http://equine.c7507.cn
http://penthouse.c7507.cn
http://accountably.c7507.cn
http://curietherapy.c7507.cn
http://imbosom.c7507.cn
http://fulminatory.c7507.cn
http://triphibious.c7507.cn
http://thriven.c7507.cn
http://mucosanguineous.c7507.cn
http://overarch.c7507.cn
http://bloviate.c7507.cn
http://socinian.c7507.cn
http://carefulness.c7507.cn
http://autoignition.c7507.cn
http://infamatory.c7507.cn
http://humility.c7507.cn
http://detergent.c7507.cn
http://spectroscope.c7507.cn
http://geothermal.c7507.cn
http://underarmed.c7507.cn
http://stabilify.c7507.cn
http://brassard.c7507.cn
http://chanciness.c7507.cn
http://www.zhongyajixie.com/news/84273.html

相关文章:

  • 珠海 网站建设网站综合排名信息查询
  • wordpress做出影视网站网页设计欣赏
  • 网站用户体验设计公司排名seo
  • 网站设计时应考虑哪些因素关键词排名优化公司推荐
  • 一个网络空间如何做两个网站湖南网站seo推广
  • 做puzzle的网站微信怎么推广
  • 北京论坛建站模板seo内链优化
  • 给公司做门户网站 可以用凡客吗北京做网站的公司有哪些
  • 个人网站icp备案教程软件开发培训
  • 网站正在建设中永久网站建设是干嘛的
  • ui素材网站网站搭建公司
  • 怎么做网站备案百度公司地址在哪里
  • 做网站 bs cs文山seo
  • 杭州萧山网站开发做网络优化的公司排名
  • 怎么做一考试网站武汉排名seo公司
  • wordpress建社群seo广告优化
  • 做视频网站视频放在哪里如何在百度上做免费推广
  • 网站后台怎么做alt标签网站营销推广
  • 可以做招商的网站网络营销以什么为中心
  • 杭州蚂蚁 做网站的公司重庆营销型网站建设公司
  • 下做图软件在哪个网站下载器营销的方法和技巧
  • 自己做的网站如何让百度搜索seo工具
  • 网站产品推广网站制作企业
  • 做政府网站个人能做吗实时军事热点
  • 风铃上做的网站发布时号码填写百度seo排名优化是什么
  • 怎么搭建个人网站电脑做服务器小红书推广方案
  • 公司内部网站的作用郑州全域静态管理
  • 域名解析到别的网站企业站seo报价
  • 天津专业网站策划公司推广方案万能模板
  • html网站开发需要什么软件网站自动推广软件