首先会想到|x|是不递减的。

于是可以枚举长度L。

再每个L设一个断点,xx必定经过两个断点。

两两断点间求最长公共前后缀,这里用hash+二分会快。

然后一波扫过去就好了。

如果找到了,hash就要重构。

来计算一下复杂度。

一共有O(n log n)个断点,每个求最长公共前后缀复杂度log,这一部分是O(n log^2 n )

长度小于 \(L \leq n\)的最多 \(n\sqrt n\)次,\(L\geq n\)最多 \(n\sqrt n\)中,所以重构复杂度: \(O(n \sqrt n)\)

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define P pair<int, int>
using namespace std; const int N = 50005, mo = 998244353, pri = 1e9 + 7, pri2 = 43313; char str[N];
int n, bz[N], tmp;
ll c[N], ni[N], s[N]; ll ksm(ll x, ll y) {
ll s = 1;
for(; y; x = x * x % mo, y >>= 1)
if(y & 1) s = s * x % mo;
return s;
} void Getsum() {
fo(i, 1, n) s[i] = (s[i - 1] + c[i] * (str[i] - 'a') % mo) % mo;
} int sum(int x, int y) {
return ((s[y] - s[x - 1] + mo) * ni[x] % mo);
} int Getq(int x, int y) {
int ans = 0;
for(int l = 1, r = tmp; l <= r;) {
int m = l + r >> 1;
if(sum(x - m + 1, x) == sum(y - m + 1, y))
ans = m, l = m + 1; else r = m - 1;
}
return ans;
} int Geth(int x, int y) {
int ans = 0;
for(int l = 1, r = n - y + 1; l <= r;) {
int m = l + r >> 1;
if(sum(x, x + m - 1) == sum(y, y + m - 1))
ans = m, l = m + 1; else r = m - 1;
}
return ans;
} int main() {
scanf("%s", str + 1); n = strlen(str + 1); c[0] = ni[0] = 1;
ni[1] = ksm(pri, mo - 2); c[1] = pri;
fo(i, 2, n) ni[i] = ni[i - 1] * ni[1] % mo, c[i] = c[i - 1] * c[1] % mo; int n0 = n; Getsum();
fo(l, 1, n) {
int xg = 0; tmp = l;
fo(i, 1, n / l) {
int x = i * l, y = x + l;
if(y > n) break;
int q = Getq(x, y), h = Geth(x, y);
if(q + h > l) {
fo(j, x - q + 1, x - q + l) bz[j] = l;
tmp = q;
xg = 1;
} else tmp = l;
}
if(xg) {
int n1 = 0;
fo(i, 1, n) if(bz[i] != l)
str[++ n1] = str[i];
n = n1;
Getsum();
}
}
fo(i, 1, n) putchar(str[i]);
}

Codeforces 319D Have You Ever Heard About the Word?的更多相关文章

  1. CF 319D(Have You Ever Heard About the Word?-模拟)

    D. Have You Ever Heard About the Word? time limit per test 6 seconds memory limit per test 256 megab ...

  2. Codeforce 水题报告

    最近做了好多CF的题的说,很多cf的题都很有启发性觉得很有必要总结一下,再加上上次写题解因为太简单被老师骂了,所以这次决定总结一下,也发表一下停课一星期的感想= = Codeforces 261E M ...

  3. CodeForces 176B Word Cut (计数DP)

    Word Cut Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  4. Codeforces Round #189 (Div. 1 + Div. 2)

    A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二 ...

  5. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  6. CodeForces - 426A(排序)

    Sereja and Mugs Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  7. Codeforces Gym 100803D Space Golf 物理题

    Space Golf 题目连接: http://codeforces.com/gym/100803/attachments Description You surely have never hear ...

  8. Codeforces Round #290 (Div. 2) C. Fox And Names dfs

    C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to ...

  9. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

随机推荐

  1. mooc_java 集合框架上 学生所选课程

    用一个集合Set存放学生所选课程接口不能实例化,所以用其实现类进行实例化 set接口不能实例化,通过HashSet这个实现类来进行实例化,需要导入包this.courses=new HashSet() ...

  2. matlab中的try...catch...end

    我们知道,matlab的代码是按行执行的,如果碰到错误行,则程序中断.try..catch可以使得可能出错代码不影响后面代码的继续执行,也可以检查,排查,解决程序的一些错误,增强代码的鲁棒性和可靠性. ...

  3. wordpress,cos-html-cache静态化后,点击数失效问题的解决方案

    装了wordpress cos-html-cache 静态插件后,生成了静态文件,post-views等点击数插件就失效了, 找了一些,包括有个js版本的,需要用到post-views插件,我也不想装 ...

  4. Sturs2 -概念讲解 第一弹

    源码下载地址:http://struts.apache.org/ struts-2.5.14.1-all.zip --所有内容 struts-2.5.14.1-apps.zip  --实例的应用 st ...

  5. C语言实现wc基本功能

    GitHub地址:https://github.com/hhx007/wc 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数. 这个项目要求写一个命令行程序,模仿已有w ...

  6. linux命令学习笔记(62)-curl命令-url下载工具

    linux curl是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载,所以是综合 传输工具,但按传统,习惯称url为下载工具. 一,curl命令参数,有好多我没有用过,也不知道 ...

  7. Android的appium实例

    1.查看Android的应用包名和activity的方法   (网上有很多种方法,这里应用的是查看日志的方法) CMD中输入>adb logcat -c                   &g ...

  8. poj1631——树状数组求LIS

    题目:http://poj.org/problem?id=1631 求LIS即可,我使用了树状数组. 代码如下: #include<iostream> #include<cstdio ...

  9. Component概念

    转自:http://www.cnblogs.com/NEOCSL/archive/2012/05/06/2485227.html 1.总结 Component就是组建的意思,可以在DefaultPro ...

  10. 六 Vue学习 首页 (下)

    一:Store介绍: state: 相当于数据 action: action去commit mutations mutation: 只有mutation 才能改变state 例: const stor ...