用 Manacher 跑出回文串长,注意这里不需要偶数长度所以不需要对串做一些奇怪的处理

然后用前缀和搞一下,计算答案时跑快速幂即可

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
namespace man {
const int N = 1100005;
char str[N], s[N<<1];
int a[N<<1]; int manacher(int len){
a[0] = 0;
int ans = 0, j;
for(int i = 0; i < len; ){
while(i-a[i]>0 && s[i+a[i]+1]==s[i-a[i]-1]) a[i]++;
if(ans < a[i])ans = a[i];
j = i+1;
while(j<=i+a[i] && i-a[i]!=i+i-j-a[i+i-j]){
a[j] = min(a[i+i-j], i+a[i]-j);
j++;
}
a[j] = max(i+a[i]-j, 0ll);
i = j;
}
return ans;
} int solve(){
int len;
len = strlen(str);
for(int i=0;i<len;i++) s[i]=str[i];
return manacher(len);
}
}
const int N = 1000005;
const int modulo = 19930726;
int qpow(int p,int q) {
ll r = 1;
for(; q; p*=p, p%=modulo, q>>=1) if(q&1) r*=p, r%=modulo;
return r;
}
int n,k,a[N];
signed main() {
scanf("%lld%lld%s",&n,&k,man::str);
man::solve();
for(int i=0;i<n;i++) {
a[man::a[i]]++;
}
for(int i=N-2;i>=0;--i) a[i]+=a[i+1];
int ans=1;
for(int i=N-2;i>=0;--i) {
ans*=qpow(i*2+1,min(a[i],k));
ans%=modulo;
k-=min(a[i],k);
}
cout<<ans;
}

[国家集训队] 拉拉队排练 - Manacher的更多相关文章

  1. Manacher【p1659】 [国家集训队]拉拉队排练

    题目描述 n个女生举牌子(只含有26个小写字母,长度为n的字符串), 如果连续的一段女生,有奇数个,并且她们手中的牌子所写的字母,从左到右和从右到左读起来一样,那么这一段女生就被称作和谐小群体. 现在 ...

  2. 洛谷 P1659 [国家集训队]拉拉队排练(Manacher)

    题目链接:https://www.luogu.com.cn/problem/P1659 思路: 首先跑一遍Manacher,用$cnt_i$记录长为$i$的回文串有多少个. 所记录的$cnt$并不是最 ...

  3. 【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)

    题目链接 马拉车+简单膜你 #include <cstdio> #include <cstring> #include <algorithm> using name ...

  4. [回文树][BZOJ2160][国家集训队]拉拉队排练

    题面 Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长的楚雨荨同学知道,帮助篮 ...

  5. luogu P1659 [国家集训队]拉拉队排练

    唔....话说好久没有发布题解了(手痒痒了 首先特别鸣谢lykkk大佬今天下午教我Manacher算法,甚是感谢 为了体现学习成果,写一篇蒟蒻版的题解(大佬勿喷 言归正传 题面——>在这儿 首先 ...

  6. P1659 [国家集训队]拉拉队排练

    思路 求出cnt和len之后,直接乘起来即可 代码 #include <cstdio> #include <algorithm> #include <cstring> ...

  7. luoguP1659 [国际集训队]拉拉队排练 manacher算法

    直接统计长度为$i$的回文子串有多少个 然后倒叙枚举长度,快速幂统计一下即可 复杂度$O(n \log n)$ #include <cstdio> #include <cstring ...

  8. [国家集训队]拉拉队排练 Manancher_前缀和_快速幂

    Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace st ...

  9. 题解 P1659 【[国家集训队]拉拉队排练】

    一眼可得PAM 如果没学过PAM的可以看这里:PAM学习小结 我们令PAM上多记录一个信息\(sum\),表示该节点表示串在原串上出现了多少次. 当我们处理完了\(sum\),对于长度\(len\)为 ...

随机推荐

  1. C#设计模式学习笔记:(13)模板方法模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7837716.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第一个模式--模 ...

  2. Android中使用SeekBar拖动条实现改变图片透明度

    场景 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为Lin ...

  3. Angularjs集成于ASP.NET MVC数据绑定重构

    这几天,对程序重构,主要针对angularjs的绑定: 第一个例子: 下面是一段html程序: 不管是name或者是ng-model的属性值,它都有一定规律"StartX"和&qu ...

  4. 题解 Luogu P3370

    讲讲这题的几种做法: 暴力匹配法 rt,暴力匹配,即把字符串存起来一位一位判相等 时间复杂度$ O(n^2·m) $ 再看看数据范围 \(n\le10^5,m\le10^3\) 当场爆炸.当然有暴力分 ...

  5. PHP-CMS代码审计(4)

    这次找了个发卡平台,url:  https://files.cnblogs.com/files/b1gstar/kamiphp.zip 从52破解上下载的 : 先把网站搭建起来. 网站没有采用mvc框 ...

  6. python生日贺卡制作以及细节问题的解决最后把python项目发布为exe可执行程序过程

    自己今天第一次做一个python生日贺卡: 效果图 参考之前有位大佬的作品,自己稍微的改造了一下下  首先:上程序 Birthday.py """ ----------- ...

  7. javascript中DOM获取和设置元素的内容、样式及效果

    getElementById() 根据id获取dom元素 没有找到则返会Null <!DOCTYPE html> <html lang="en"> < ...

  8. Upx 压缩go编译的程序 frp

    1. frp 程序占用大 .路由器 不够空间 2. UPX 下载地址       https://github.com/upx/upx/releases/ 3.  压缩命令  upx.exe -9 C ...

  9. 解决kbmMW Scheduler在任务中停止任务遇到的问题

    procedure TCustomGridViewCameraDoc.InitSchedule; begin Scheduler.Schedule( procedure(const ASchedule ...

  10. Tomcat配置绝对路径

    JSP访问项目工程下的地址 <video width="640" height="264" controls src="http://local ...