当前位置:网站首页>2022杭电多校第一场01
2022杭电多校第一场01
2022-08-05 05:09:00 【吃花椒的妙酱】
题意:设F(i)表示s串的一个前缀[1…i]的中所有区间交长度为k的倍数的board串数量,求 ∏ i = 1 ∣ s ∣ ( f ( i ) + 1 ) \prod_{i=1}^{|s|}{(f(i)+1)} ∏i=1∣s∣(f(i)+1)
做法:z函数,差分
先求出s串的z函数(exkmp),设z[i]表示s串的z函数。可以将每个前缀的board转化为每个后缀与原串前缀的lcp,考虑每个后缀[i…n]的贡献,
画个图,容易发现当z[i]>=i时,此时这个后缀与原串的lcp部分才有贡献。
此时第2*(i-1)+k,2*(i-1)+2k,2*(i-1)+3k…个前缀都能算到这部分的贡献。差分一下即可,不过距离是k。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
#define _for(i,a,b) for(int i=(a) ;i<=(b) ;i++)
#define _rep(i,a,b) for(int i=(a) ;i>=(b) ;i--)
#define mst(v,s) memset(v,s,sizeof(v))
#define pii pair<int ,int >
#define pb(v) push_back(v)
#define all(v) v.begin(),v.end()
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x7f7f7f7f7f7f7f7f
#define endl "\n"
#define fi first
#define se second
#define ls p<<1
#define rs p<<1|1
#define lson p<<1,l,mid
#define rson p<<1|1,mid+1,r
#define AC return 0
#define ldb long double
const int N=2e6+5;
const int mod=998244353;
const double eps=1e-8;
ll nxt[N];
void qnxt(char *c){
int len = strlen(c);
int p = 0, k = 1, l;
nxt[0] = len;
while(p + 1 < len && c[p] == c[p + 1]) p++;
nxt[1] = p;
for(int i = 2; i < len; i++){
p = k + nxt[k] - 1;
l = nxt[i - k];
if(i + l <= p) nxt[i] = l;
else{
int j = max(0ll, p - i + 1ll);
while(i + j < len && c[i + j] == c[j]) j++;
nxt[i] = j;
k = i;
}
}
}
int lb,tag[N];
char b[N];
ll ans;
signed main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
IOS;
int T;cin>>T;
while( T-- ){
cin >> b;
int k;cin>>k;
qnxt(b);
lb = strlen(b);
//枚举以i开始的后缀,贡献差分
for(int i=0 ;i<lb ;i++){
int X = nxt[i];
int id = i+1;//真实下标
//找最左和最右的pre[1...i]算贡献
if( X>=id && X-id+1 >= k){
tag[2*(id-1) + k]++;//左
int t = (X-id+1)/k*k;
if( 2*(id-1) + t + k <= lb ) tag[2*(id-1) + t + k]--;
}
}
int ans=1;
_for(i,1,lb){
if( i-k>=1) tag[i] = tag[i] + tag[i-k];
ans = ans * (tag[i]+1)%mod;
}
cout<<ans<<endl;
_for(i,0,lb+k){
tag[i]=0;
}
}
return 0;
}
边栏推荐
- C语言-大白话理解原码,反码和补码
- 虚证、实证如何鉴别?
- Requests库部署与常用函数讲解
- Day14 jenkins deployment
- Homework 8.4 Interprocess Communication Pipes and Signals
- Reverse theory knowledge 4
- for..in和for..of的区别
- Flutter Learning 4 - Basic UI Components
- Why did you start preparing for the soft exam just after the PMP exam?
- Use IDEA to connect to TDengine server
猜你喜欢
Machine Learning Overview
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
RL强化学习总结(一)
[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
Day019 Method overriding and introduction of related classes
University Physics---Particle Kinematics
类的底层机制
一篇博客通关Redis技术栈
Flutter 父子组件如何都能收到点击事件
Excel画图
随机推荐
number_gets the specified number of decimals
Day019 方法重写与相关类的介绍
『递归』递归概念与典型实例
入口点注入
开发一套高容错分布式系统
There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space
how to measure distance from point to face in creo
Flutter learning 2-dart learning
【cesium】Load and locate 3D Tileset
1068 Find More Coins
The log causes these pits in the thread block, you have to guard against
dedecms后台生成提示读取频道信息失败的解决方法
Understanding and use of C# on set() and get() methods
数字孪生技术在电力系统中的应用现状
Please write the SparkSQL statement
Day14 jenkins部署
Flutter学习5-集成-打包-发布
C语言-大白话理解原码,反码和补码
请写出SparkSQL语句
Flutter learning 5-integration-packaging-publish