Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)
http://codeforces.com/contest/1129/problem/C
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pqueue priority_queue
#define NEW(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x&(-x))
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define lc (d<<1)
#define rc (d<<1|1)
const double pi=4.0*atan(1.0);
const double e=exp(1.0);
const int maxn=1e6+;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+;
const ULL base=1e7+;
using namespace std;
LL a[maxn],b[maxn],Next[maxn];
LL dp[][];
void get_next(int m){
Next[]=-;
int k=-;
int j=;
while(j<m){
while(k>-&&b[k]!=b[j]){
k=Next[k];
}
if(b[k]==b[j]||k==-){
k++;
}
Next[++j]=k;
}
}
bool kmp(int n,int m){
int k=;
for(int i=n-m+;i<=n;i++){
b[k++]=a[i];
}
get_next(m);
k=;
for(int i=;i<n;i++)
{
while(k>&&b[k]!=a[i]){
k=Next[k];
}
if(b[k]==a[i]){
k++;
}
if(k==m){
return ;
}
}
return ;
}
bool check(int l){
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
return ;
}
int main(){
int n;
LL sum=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(i==){
dp[][]=;
printf("1\n");
}
else{
int l=,r=i;
int ans=;
while(l<=r){
int mid=(l+r)>>;
if(kmp(i,mid)){
l=mid+;
ans=max(ans,mid);
}
else{
r=mid-;
}
}
dp[i][i]=;
if(i>) dp[i-][i]=;
if(i>) dp[i-][i]=;
if(i>&&check(i-)) dp[i-][i]=;
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i][i];
dp[j][i]%=mod;
}
for(int j=i-ans;j>=;j--){
sum+=dp[j][i];
sum%=mod;
}
printf("%lld\n",sum);
}
}
}
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)的更多相关文章
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2
A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)
A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)C. Morse Code
题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)
A - Toy Train 很显然,一个站有多少个糖,那么就要从这个点运多少次.设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段.很显然最后一段越小越好. 然后枚举起点后, ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解
A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...
- Codeforces Round 542 (Div. 2)
layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #542 题解
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...
- int和integer;Math.round(11.5)和Math.round(-11.5)
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
随机推荐
- Azure CosmosDB (11) MongoDB概念
<Windows Azure Platform 系列文章目录> Azure Cosmos DB兼容MongoDB的API,下表将帮助我们更容易理解MongoDB中的一些概念: SQL概念 ...
- 子线程更新UI界面的2种方法
一.一般我们都会在子线程完成一些耗时的操作. 1.Android中消息机制: 2.知识点: Message:消息,其中包含了消息ID,消息处理对象以及处理的数据等,由MessageQueue统一列队, ...
- Metabase研究 开源的数据报表
https://blog.csdn.net/bin330720911/article/details/79273317 https://blog.csdn.net/qq_35902833/articl ...
- nginx1.14.0版本高可用——keepalived双机热备
nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...
- 基于STM8的IIC协议---STM8-第五章
1. 综述 I2C(IIC,Inter-Integrated Circuit),两线式串行总线,由PHILIPS公司开发用于连接微控制器及其外围设备. 它是由数据线SDA和时钟SCL构成的串行总线,可 ...
- 提问:MicrosoftUnderlying input stream returned zero bytes
报错信息:MicrosoftUnderlying input stream returned zero bytes 报错截图: 查阅资料后,提示 jdbc的bug,不能将一个"NULL&qu ...
- [STM32F103]PWM输入捕获配置
l 初始化定时器和通道对应IO的时钟. l 初始化IO口,模式为输入: GPIO_Init(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0 ...
- [STM32F103]定时器中断
l 使能定时器时钟. RCC_APB1PeriphClockCmd(); l 初始化定时器,配置ARR,PSC. TIM_TimeBaseInit(); l 开启定时器中断,配置NVIC. void ...
- 在chrome console中添加jQuery
由于现有seajs等封装,jQuery等已不在全局暴露,即使网站中已使用jQuery,在console也使用不了. 在chrome中可以用以下代码加入jQuery: fetch('http://cod ...
- GetBuffer 与ToArray区别,解决问题场景
GetBuffer 是把 stream 中的 buffer 的引用传递出来, buffer 的大小是由 stream的 Capacity来决定的. 因为只是地址的引用传递,所以 GetBuffer() ...