对拍没错。。莫名wa了

利用容斥求每个串的重复子串

其实就是找到每个元素能扩展到的最大元素

即(rr-i)*(i-lr)*(w[i]-kk) 就可以了

然后处理这个先离散化再搞

另外是x y要清空

#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const ll N=2e5+;
const double pi=acos(-1.0);
ll height[N],rank[N],sa[N],c[N],x[N],y[N],a[N],n,m,kk;
char s[N];
void asa(ll n,ll m)
{
memset(x,,sizeof(x));
memset(y,,sizeof(y));
ll p=,f=;
for (ll i=;i<=m;i++) c[i]=;
for (ll i=;i<=n;i++) c[x[i]=a[i]]++;
for (ll i=;i<=m;i++) c[i]+=c[i-];
for (ll i=n;i;i--) sa[c[x[i]]--]=i;
for(ll i=;i<=n&&p<=n;i<<=)
{
p=;
for (ll j=n-i+;j<=n;j++) y[++p]=j;
for (ll j=;j<=n;j++)
if (sa[j]>i) y[++p]=sa[j]-i;
for (ll j=;j<=m;j++) c[j]=;
for (ll j=;j<=n;j++) c[x[y[j]]]++;
for (ll j=;j<=m;j++) c[j]+=c[j-];
for (ll j=n;j;j--) sa[c[x[y[j]]]--]=y[j];
swap(x,y); x[sa[]]=; p=;
for (ll j=;j<=n;j++)
x[sa[j]]=y[sa[j]]==y[sa[j-]]&&y[sa[j]+i]==y[sa[j-]+i]
?p-:p++;
m=p;
}
for (ll i=;i<=n;i++) rank[sa[i]]=i;
for (ll i=;i<=n;i++)
{
ll j=sa[rank[i]-];
if (f) f--;
while (a[i+f]==a[j+f]) f++;
height[rank[i]]=f;
}
}
struct re{
ll a,b;
};
bool cmp(re x,re y)
{
return(x.a<y.a);
}
ll lr[N],rr[N];
ll get_ans()
{
re a[N],b[N];
for (ll i=;i<=n;i++)
a[i].a=height[i],a[i].b=i;
sort(a+,a++n,cmp);
for (ll i=;i<=n;i++)
b[a[i].b].a=i,b[a[i].b].b=a[i].a;
ll j;
sort(a+,a++n,cmp);
b[].a=-; b[n+].a=-;
for (ll i=;i<=n;i++)
{
j=i-;
while (b[i].a<b[j].a) j=lr[j];
lr[i]=j;
}
for (ll i=n;i>=;i--)
{
j=i+;
while (b[i].a<b[j].a) j=rr[j];
rr[i]=j;
}
ll ans=;
for (ll i=;i<=n;i++)
if (b[i].b>=kk) ans+=(b[i].b-kk+)*(i-lr[i])*(rr[i]-i);
return(ans);
}
string s1,s2,stmp;
int main()
{
freopen("noip.in","r",stdin);
freopen("noip.out","w",stdout);
while (cin>>kk&&kk)
{
cin>>s1>>s2;
string str=s1;
memset(s,,sizeof(s));
strcpy(s,str.c_str());
n=strlen(s);
for (ll i=;i<=n;i++)
a[i]=s[i-]-' ';
ll x1,x2,x3;
asa(n,);
x1=get_ans();
stmp=s2;
memset(s,,sizeof(s));
strcpy(s,stmp.c_str());
n=strlen(s);
for (ll i=;i<=n;i++)
a[i]=s[i-]-' ';
asa(n,); x2=get_ans();
stmp=s1+'%'+s2; memset(s,,sizeof(s));
strcpy(s,stmp.c_str());
n=strlen(s);
for (ll i=;i<=n;i++)
a[i]=s[i-]-' ';
asa(n,);
x3=get_ans();
cout<<x3-x2-x1<<endl;
}
return ;
}

poj 3415的更多相关文章

  1. POJ 3415 不小于k的公共子串的个数

    Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9248   Accepted: 3071 ...

  2. POJ 3415 Common Substrings 【长度不小于 K 的公共子串的个数】

    传送门:http://poj.org/problem?id=3415 题意:给定两个串,求长度不小于 k 的公共子串的个数 解题思路: 常用技巧,通过在中间添加特殊标记符连接两个串,把两个串的问题转换 ...

  3. POJ 3415 (后缀自动机)

    POJ 3415 Common Substrings Problem : 给两个串S.T (len <= 10^5), 询问两个串有多少个长度大于等于k的子串(位置不同也算). Solution ...

  4. POJ - 2774~POJ - 3415 后缀数组求解公共字串问题

    POJ - 2774: 题意: 求解A,B串的最长公共字串 (摘自罗穗骞的国家集训队论文): 算法分析: 字符串的任何一个子串都是这个字符串的某个后缀的前缀. 求 A 和 B 的最长 公共子串等价于求 ...

  5. POJ 3415 Common Substrings(后缀数组 + 单调栈)题解

    题意: 给两个串\(A.B\),问你长度\(>=k\)的有几对公共子串 思路: 先想一个朴素算法: 把\(B\)接在\(A\)后面,然后去跑后缀数组,得到\(height\)数组,那么直接\(r ...

  6. POJ 3415 后缀数组

    题目链接:http://poj.org/problem?id=3415 题意:给定2个串[A串和B串],求两个串公共子串长度大于等于k的个数. 思路:首先是两个字符串的问题.所以想用一个'#'把两个字 ...

  7. poj 3415 Common Substrings(后缀数组+单调栈)

    http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Sub ...

  8. poj 3415 Common Substrings

    题目链接:http://poj.org/problem?id=3415 题目分类:后缀数组 题意:给出两个串和一个数字k,求两个串的公共字串大于等于k的数目 代码: //#include<bit ...

  9. poj 3415 Common Substrings - 后缀数组 - 二分答案 - 单调栈

    题目传送门 传送点I 传送点II 题目大意 给定串$A, B$,求$A$和$B$长度大于等于$k$的公共子串的数量. 根据常用套路,用一个奇怪的字符把$A$,$B$连接起来,然后二分答案,然后按mid ...

  10. POJ 3415 Common Substrings(长度不小于K的公共子串的个数+后缀数组+height数组分组思想+单调栈)

    http://poj.org/problem?id=3415 题意:求长度不小于K的公共子串的个数. 思路:好题!!!拉丁字母让我Wa了好久!!单调栈又让我理解了好久!!太弱啊!! 最简单的就是暴力枚 ...

随机推荐

  1. fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory(转)

    fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory 解决办法:(Vs2013中) 项目--右键--属性--配置属 ...

  2. [洛谷P3948]数据结构 题解(差分)

    [洛谷P3948]数据结构 Description 最开始的数组每个元素都是0 给出n,opt ,min,max,mod 在int范围内 A: L ,R ,X 表示把[l,R] 这个区间加上X(数组的 ...

  3. luogu P4342 [IOI1998]Polygon

    IOI早期这么多dp? 题目要求断掉环上的一边,我们可以断环为链,开两倍数组 容易想到dp,设\(f_{i,j}\)为区间\([i,j]\)的最大值,然后就是个枚举断点的区间dp 不过可能会有负数出现 ...

  4. 阿里云3台机器组成集群配置ssh免密码登陆

    1 查询阿里云局网ip 注意:需要配置同一地区同一可用区的机器 才是一个局网 2 配置好hosts文件 3 hostname确认也是正确的 4 生成公钥私钥 三台机器同样操作 ssh-keygen - ...

  5. jquery 学习(六) - 事件绑定

    HTML <!--绑定事件--> <div class="a1"> <button class="bt">按钮</bu ...

  6. python - socketserver 模块应用

    server端: import socketserver import subprocess import json import struct class MyTCPHandler(socketse ...

  7. select 1

    select 1 from mytable;与select anycol(目的表集合中的任意一行) from mytable;与select * from mytable 作用上来说是没有差别的,都是 ...

  8. js 鼠标拖拽元素

    基础知识 event.clientX.event.clientY 鼠标相对于浏览器窗口可视区域的X,Y坐标(窗口坐标),可视区域不包括工具栏和滚动条.IE事件和标准事件都定义了这2个属性 event. ...

  9. 【转】Python之日期与时间处理模块(date和datetime)

    [转]Python之日期与时间处理模块(date和datetime) 本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常 ...

  10. xpath与nodejs解析xml

    测试xpath的工具 http://www.freeformatter.com/xpath-tester.html#ad-output http://www.xpathtester.com/test ...