【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)
题目链接
马拉车+简单膜你
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 11000010;
const int MOD = 19930726;
char b[MAXN], a[MAXN << 1];
int hw[MAXN << 1], ans = 1, n, c[MAXN];
#define ll long long
ll now, m;
int fast_pow(int a, ll k){
    int ans = 1;
    while(k){
       if(k & 1) ans = (ll)ans * a % MOD;
       a = (ll) a * a % MOD;
       k >>= 1;
    }
    return ans;
}
int main(){
    scanf("%d%lld", &n, &m);
    scanf("%s", b);
    a[0] = a[1] = '#';
    for(int i = 0; i < n; ++i)
       a[(i << 1) + 2] = b[i], a[(i << 1) + 3] = '#';
    int maxright = 0, mid; n = (n << 1) + 3;
    for(int i = 1; i < n; ++i){
       if(i < maxright)
         hw[i] = min(hw[(mid << 1) - i], hw[mid] + mid - i);
       else hw[i] = 1;
       while(a[i + hw[i]] == a[i - hw[i]]) ++hw[i];
       if(hw[i] + i > maxright){
         maxright = hw[i] + i;
         mid = i;
       }
       ++c[hw[i] - 1];
    }
    for(int i = (n - 3) >> 1; i; --i){
        if(i & 1 ^ 1) continue;
        now += c[i];
        if(m <= now){ ans = (ll) ans * fast_pow(i, m) % MOD; m = 0; break; }
        m -= now; ans = (ll) ans * fast_pow(i, now) % MOD;
    }
    if(m) ans = -1;
    printf("%d\n", ans);
    return 0;
}
												
											【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)的更多相关文章
- 洛谷 P1659 [国家集训队]拉拉队排练(Manacher)
		
题目链接:https://www.luogu.com.cn/problem/P1659 思路: 首先跑一遍Manacher,用$cnt_i$记录长为$i$的回文串有多少个. 所记录的$cnt$并不是最 ...
 - luogu P1659 [国家集训队]拉拉队排练
		
唔....话说好久没有发布题解了(手痒痒了 首先特别鸣谢lykkk大佬今天下午教我Manacher算法,甚是感谢 为了体现学习成果,写一篇蒟蒻版的题解(大佬勿喷 言归正传 题面——>在这儿 首先 ...
 - [国家集训队] 拉拉队排练 - Manacher
		
用 Manacher 跑出回文串长,注意这里不需要偶数长度所以不需要对串做一些奇怪的处理 然后用前缀和搞一下,计算答案时跑快速幂即可 #include <bits/stdc++.h> us ...
 - P1659 [国家集训队]拉拉队排练
		
思路 求出cnt和len之后,直接乘起来即可 代码 #include <cstdio> #include <algorithm> #include <cstring> ...
 - 模板—点分治A(容斥)(洛谷P2634 [国家集训队]聪聪可可)
		
洛谷P2634 [国家集训队]聪聪可可 静态点分治 一开始还以为要把分治树建出来……• 树的结构不发生改变,点权边权都不变,那么我们利用刚刚的思路,有两种具体的分治方法.• A:朴素做法,直接找重心, ...
 - [洛谷P1527] [国家集训队]矩阵乘法
		
洛谷题目链接:[国家集训队]矩阵乘法 题目背景 原 <补丁VS错误>请前往P2761 题目描述 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. 输入输出格式 输入 ...
 - 洛谷 P4555 [国家集训队]最长双回文串 解题报告
		
P4555 [国家集训队]最长双回文串 题目描述 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为abc,逆序为cba,不相同). 输入长度为\(n\)的串 ...
 - 洛谷P1501 [国家集训队]Tree II(LCT,Splay)
		
洛谷题目传送门 关于LCT的其它问题可以参考一下我的LCT总结 一道LCT很好的练习放懒标记技巧的题目. 一开始看到又做加法又做乘法的时候我是有点mengbi的. 然后我想起了模板线段树2...... ...
 - 洛谷P2619 [国家集训队2]Tree I(带权二分,Kruscal,归并排序)
		
洛谷题目传送门 给一个比较有逼格的名词--WQS二分/带权二分/DP凸优化(当然这题不是DP). 用来解决一种特定类型的问题: 有\(n\)个物品,选择每一个都会有相应的权值,需要求出强制选\(nee ...
 - 洛谷 P1407 [国家集训队]稳定婚姻 解题报告
		
P1407 [国家集训队]稳定婚姻 题目描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关. 25岁的 ...
 
随机推荐
- 算法练习题---罗马数字转int
			
连接:https://leetcode-cn.com/problems/roman-to-integer/submissions/ 题目: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 ...
 - Spring Boot 支持 HTTPS 如此简单,So easy!
			
这里讲的是 Spring Boot 内嵌式 Server 打 jar 包运行的方式,打 WAR 包部署的就不存在要 Spring Boot 支持 HTTPS 了,需要去外部对应的 Server 配置. ...
 - (转载)基于Linux C的socket抓包程序和Package分析
			
转载自 https://blog.csdn.net/kleguan/article/details/27538031 1. Linux抓包源程序 在OSI七层模型中,网卡工作在物理层和数据链路层的MA ...
 - 子查询优化 - Hyper
			
Unnesting Arbitrary Queries - T Neumann, A KemperThe Complete Story of Joins (in HyPer) - Thomas Neu ...
 - Oracle系列三 过滤和排序
			
WHERE子句 使用WHERE 子句,将不满足条件的行过滤掉. 示例: SELECT employee_id, last_name, job_id, department_id FROM employ ...
 - Global.asax.cs  为 /.aspx 执行子请求时出错。 Server.Transfer
			
x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...
 - 相位展开(phase unwrapping)算法研究与实践
			
1. 什么是相位展开? 相位展开(Phase Unwrapping)是一个经典的信号处理问题,它指的是从值区间中恢复原始相位值(原因在于:计算相位时,运用反正切函数,则相位图中提取的相位都是包裹在一个 ...
 - [LeetCode] 206. Reverse Linked List 反向链表
			
Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. ...
 - 下载youtube视频到本地
			
https://www.clipconverter.cc/ 先通过上面的网站对youtube视频的url 进行解析获得下载链接地址 获得链接地址后 可通过阿里云香港服务器去下载 , 速度比较快 在阿里 ...
 - webpack 4.0改版问题
			
4.0之后的打包方式: webpack --mode development src/index.js --output-filename app.js --output-path dist