传送门

感觉智商莫名其妙的就变低了……写这题的时候死活想不出来……

做法其实不难……

题目要求形如ABA的串的个数,我们可以枚举A的长度,利用标记关键点的方法统计答案。设枚举到的答案为k,每k个点标记一个关键点,显然每个A只会恰好包含一个关键点,那么我们枚举每个关键点$i$,求一下它和$i+m+l$前后各能匹配到哪儿,显然答案应该加上能匹配的长度。注意为了防止重复计算需要把LCP和LCS(最长公共后缀)对$k$取min。

求LCP和LCS我是用hash写的,一开始base选的2147483647然后WA了,换成123456789和233333333倒是都能过……什么鬼……

 /**************************************************************
Problem: 2119
User: hzoier
Language: C++
Result: Accepted
Time:3664 ms
Memory:1800 kb
****************************************************************/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const unsigned long long base=233333333ll;
unsigned long long gethash(int,int);
int LCP(int,int);
int LCS(int,int);
unsigned long long h[maxn],pw[maxn];
long long ans=;
int n,m,a[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)scanf("%d",&a[i]);
for(int i=n;i;i--)a[i]-=a[i-];
n--;
for(int i=n;i;i--)h[i]=h[i+]*base+a[i]+base+1ull;
pw[]=;
for(int i=;i<=n;i++)pw[i]=pw[i-]*base;
for(int l=;m+(l<<)<=n;l++){
for(int i=l;i+m+l<=n;i+=l){
int tmpa=min(LCS(i,i+m+l),l),tmpb=min(LCP(i,i+m+l),l);
if(tmpa+tmpb>l)ans+=tmpa+tmpb-l;
}
}
printf("%lld",ans);
return ;
}
inline unsigned long long gethash(int x,int l){return h[x]-h[x+l]*pw[l];}
int LCP(int x,int y){
if(x>y)swap(x,y);
int L=,R=n-y+;
while(L<=R){
int M=(L+R)>>;
if(gethash(x,M)==gethash(y,M))L=M+;
else R=M-;
}
return R;
}
int LCS(int x,int y){
if(x>y)swap(x,y);
int L=,R=x;
while(L<=R){
int M=(L+R)>>;
if(gethash(x-M+,M)==gethash(y-M+,M))L=M+;
else R=M-;
}
return R;
}

bzoj2119 股市的预测的更多相关文章

  1. [NOI2016]优秀的拆分&&BZOJ2119股市的预测

    [NOI2016]优秀的拆分 https://www.lydsy.com/JudgeOnline/problem.php?id=4650 题解 如果我们能够统计出一个数组a,一个数组b,a[i]表示以 ...

  2. BZOJ2119 股市的预测 字符串 SA ST表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9069171.html 题目传送门 - BZOJ2119 题意 给定一个股票连续$n$个时间点的价位,问有多少段 ...

  3. BZOJ2119: 股市的预测(后缀数组)

    Description 墨墨的妈妈热爱炒股,她要求墨墨为她编写一个软件,预测某只股票未来的走势.股票折线图是研究股票的必备工 具,它通过一张时间与股票的价位的函数图像清晰地展示了股票的走势情况.经过长 ...

  4. bzoj千题计划312:bzoj2119: 股市的预测(后缀数组+st表)

    https://www.lydsy.com/JudgeOnline/problem.php?id=2119 题意:将给定数组差分后,求ABA形式的字串个数,要求|B|=m,|A|>0 1.后缀数 ...

  5. 【BZOJ2119】股市的预测 后缀数组+分块

    [BZOJ2119]股市的预测 Description 墨墨的妈妈热爱炒股,她要求墨墨为她编写一个软件,预测某只股票未来的走势.股票折线图是研究股票的必备工具,它通过一张时间与股票的价位的函数图像清晰 ...

  6. 【BZOJ-2119】股市的预测 后缀数组

    2119: 股市的预测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 334  Solved: 154[Submit][Status][Discuss ...

  7. BZOJ 2119: 股市的预测 [后缀数组 ST表]

    2119: 股市的预测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 331  Solved: 153[Submit][Status][Discuss ...

  8. 【BZOJ 2119】 2119: 股市的预测 (后缀数组+分块+RMQ)

    2119: 股市的预测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 404  Solved: 188 Description 墨墨的妈妈热爱炒股,她 ...

  9. BZOJ 2119: 股市的预测 SA

    2119: 股市的预测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 434  Solved: 200[Submit][Status][Discuss ...

随机推荐

  1. 关于云主机Thinkphp框架Session跨页失效的问题

    在网站部署到云主机之后,前台一直能够正常显示,后台确登录不上去,验证码也无法显示,研究半天,才确定是Session跨页传递失效的问题.找网上各种解决方法,都是关于Php.ini文件的设置,可又解决不了 ...

  2. mybatis的CRUD实例(三)

    前面的文章我们已经实现了根据id查询用户信息的功能,下面我们进行其他业务功能的实现. 一.根据用户名模糊查询用户列表 查询使用的sql : select * from user where usern ...

  3. BZOJ - 3295 三维偏序 空间转换

    题意:动态逆序对,共m次删除操作,求每次操作前的逆序对个数 删除操作转换为添加操作,首先对时间a进行简单排序 然后用cdq分治处理b维,树状数组处理c维 此时需要求的是对于某有序组\((a,b,c)\ ...

  4. JVM 统计监测命令

    参考 深入理解JVM(七)——性能监控工具 JVM性能调优监控工具专题一 JVM调优总结 + jstat 分析 1. 进入 jdk 目录 cd /usr/local/jdk/bin 2. 查询所有 j ...

  5. oracle client 低于 oracle server 端,导致报错ORA-01882

    https://forums.toadworld.com/t/ora-01882-when-i-want-to-view-records-con-dba-scheduler-jobs-toad-10- ...

  6. linux新增特性timerfd

    https://blog.csdn.net/shreck66/article/details/49745149

  7. LinuxShell脚本编程7-for和while

    1.for的使用 #! /bin/bash ` do echo $a done 表示:a初始值为1,然后a=a+2的操作,一直到a<=10为止 for((i=1;i<=10;i=i+2)) ...

  8. MySQL的优化(大纲)

    参考:http://www.cnblogs.com/villion/archive/2009/07/23/1893765.html#3031899 MySQL的优化,主要可以考虑以下四方面: 1.数据 ...

  9. Hibernate 一对一映射(惟一外键)

  10. Signal Handling--ref

    http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html A signal is a software interrupt d ...