用 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++中的public、protected和private

    访问权限控制 一个类的public的成员变量.成员函数,可以通过类的实例变量进行访问. 一个类的protected的成员变量.成员函数,无法通过类的实例变量进行访问,但是可以通过类的友元函数.友元类进 ...

  2. NServiceBus 入门到精通(一)

    什么是NServiceBus?NServiceBus 是一个用于构建企业级 .NET系统的开源通讯框架.它在消息发布/订阅支持.工作流集成和高度可扩展性等方面表现优异,因此是很多分布式系统基础平台的理 ...

  3. 在非NDK编译条件下使用Android Log函数

    解决的需求 有些时候不能在NDK环境编译,或者使用NDK编译会颇费周折,然后又想使用Android系统自带的Log类方法,那么我们就可以使用dlopen来实现我们的目的.比如在OpenCV中添加And ...

  4. Maven项目的目录问题

    创建maven项目,使不使用骨架都行. java项目的目录 src/main  项目 java存放.java文件,resources存放静态资源.配置文件.映射文件. 静态资源一般在resources ...

  5. The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.

    在eclipse里运行jsp文件最初迟迟没有反应,重启报了这个错误,tomcat的端口设置有问题.需要打开服务器设置一下端口号. 点击Servers,如果没有这一项,按照Window-Show Vie ...

  6. vue中this在回调函数中的使用

    this在各类回调中使用: 如果是普通函数是没法使用的 所以需要先将this.变量赋值给新的变量,然后才能在回调函数中使用 例如: refund: function (id) { if (!this. ...

  7. IBM x3250m5安装redhat 6.5 加载raid卡驱动

    原文地址:http://www.i5i6.net/post/118.html 1. 下载对应raid卡驱动 for redhat6.5 x64(如本次x3250 m5 c100阵列卡驱动 lsi_dd ...

  8. vue-cli-service 报错

    错误内容: vue-cli-service serve /bin/sh: vue-cli-service: command not found error Command failed with ex ...

  9. 41.Python中加载静态文件

    在一个网页中,不仅仅只有一个html骨架,还需要css样式文件,js执行文件以及一些图片等.因此在DTL中加载静态文件时一个必须要解决的问题.在DTL中,使用static标签来加载静态文件.要使用st ...

  10. Document节点

    概述 document节点对象代表整个文档,每张网页都有自己的document对象.window.document属性就指向这个对象.只要浏览器开始载入 HTML 文档,该对象就存在了,可以直接使用. ...