bzoj2119 股市的预测
感觉智商莫名其妙的就变低了……写这题的时候死活想不出来……
做法其实不难……
题目要求形如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 股市的预测的更多相关文章
- [NOI2016]优秀的拆分&&BZOJ2119股市的预测
[NOI2016]优秀的拆分 https://www.lydsy.com/JudgeOnline/problem.php?id=4650 题解 如果我们能够统计出一个数组a,一个数组b,a[i]表示以 ...
- BZOJ2119 股市的预测 字符串 SA ST表
原文链接https://www.cnblogs.com/zhouzhendong/p/9069171.html 题目传送门 - BZOJ2119 题意 给定一个股票连续$n$个时间点的价位,问有多少段 ...
- BZOJ2119: 股市的预测(后缀数组)
Description 墨墨的妈妈热爱炒股,她要求墨墨为她编写一个软件,预测某只股票未来的走势.股票折线图是研究股票的必备工 具,它通过一张时间与股票的价位的函数图像清晰地展示了股票的走势情况.经过长 ...
- bzoj千题计划312:bzoj2119: 股市的预测(后缀数组+st表)
https://www.lydsy.com/JudgeOnline/problem.php?id=2119 题意:将给定数组差分后,求ABA形式的字串个数,要求|B|=m,|A|>0 1.后缀数 ...
- 【BZOJ2119】股市的预测 后缀数组+分块
[BZOJ2119]股市的预测 Description 墨墨的妈妈热爱炒股,她要求墨墨为她编写一个软件,预测某只股票未来的走势.股票折线图是研究股票的必备工具,它通过一张时间与股票的价位的函数图像清晰 ...
- 【BZOJ-2119】股市的预测 后缀数组
2119: 股市的预测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 334 Solved: 154[Submit][Status][Discuss ...
- BZOJ 2119: 股市的预测 [后缀数组 ST表]
2119: 股市的预测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 331 Solved: 153[Submit][Status][Discuss ...
- 【BZOJ 2119】 2119: 股市的预测 (后缀数组+分块+RMQ)
2119: 股市的预测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 404 Solved: 188 Description 墨墨的妈妈热爱炒股,她 ...
- BZOJ 2119: 股市的预测 SA
2119: 股市的预测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 434 Solved: 200[Submit][Status][Discuss ...
随机推荐
- linux使用rsync、inotify-tools实现多台服务器文件实时同步
需求:将本地192.168.1.10上的/data/wwwroot目录同步到 1.来源服务器上安装rsync.inotify-tools yum -y install rsync yum -y ins ...
- noip提高组模拟赛(QBXT)T2
T2count题解 [ 问题描述]: 小 A 是一名热衷于优化各种算法的 OIER,有一天他给了你一个随机生成的 1~n 的排列, 并定 义区间[l,r]的价值为: \[ \huge C_{l,r}= ...
- js计算器案例
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>j ...
- 原生js 实现旋转木马
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 进阶篇:4.3)DFA设计指南:防错设计( 防呆设计)
本章目的:每一个装配步骤都有设计防错. 1.前言 关于防错设计,作者有想说的话: 1)防错设计是DFA重要的一条.因为太过重要,作者单独开一分章写! 2)只有理解了设计防错的重要,才会去设计防错特征. ...
- 51nod1238. 最小公倍数之和 V3(数论)
题目链接 https://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题解 本来想做个杜教筛板子题结果用另一种方法过了...... 所谓 ...
- Bowen
Advertise Window大小 注册表键值位于:regedit->HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Pa ...
- python 继承与组合
一.组合 #老师 课程 生日 class Course: def __init__(self,name,period,price): self.name = name self.period = pe ...
- python四则运算2.0
github项目地址: https://github.com/kongkalong/python PSP 预估耗时(分钟) Planning .Estimate 48*60 Development . ...
- windows下hla编译环境配置(转)
原文地址:http://blog.chinaunix.net/uid-20548989-id-1667169.html HLA简介 HLA,英文"High Level Ass ...