URAL 2040 Palindromes and Super Abilities 2(回文树)
Time Limit: 1MS | Memory Limit: 102400KB | 64bit IO Format: %I64d & %I64u |
Description
Two substrings are considered distinct if they are different as strings. Which nnumbers will be said by Misha if it is known that he is never wrong?
Input
Output
prefixs1 … si−1. The first number in the output should be one.
Sample Input
input | output |
---|---|
abbbba |
111111 |
Notes
Source
Problem Source: Ural FU Dandelion contest. Petrozavodsk training camp. Summer 2014
#include <iostream>
#include <string.h> #include <stdlib.h>
#include <math.h>
#include <stdio.h> using namespace std;
typedef long long int LL;
const int MAX=5*1e6;
const int maxn=4*1e6+5;
char str[MAX+5];
struct Tree
{
int next[maxn][2];
int fail[MAX+5];
int len[MAX+5];
int s[MAX+5];
int last,n,p;
int new_node(int x)
{
memset(next[p],0,sizeof(next[p]));
len[p]=x;
return p++;
}
void init()
{
p=0;
new_node(0);
new_node(-1);
last=0;n=0;
s[0]=-1;
fail[0]=1;
}
int get_fail(int x)
{
while(s[n-len[x]-1]!=s[n])
x=fail[x];
return x;
}
int add(int x)
{
x-='a';
s[++n]=x;
int cur=get_fail(last);
if(!(last=next[cur][x]))
{
int now=new_node(len[cur]+2);
fail[now]=next[get_fail(fail[cur])][x];
next[cur][x]=now;
last=now;
return 1;
}
return 0;
} }tree;
char ans[MAX+5];
int main()
{
while(scanf("%s",str)!=EOF)
{ tree.init();
int i;
for( i=0;str[i];i++)
{
if(!tree.add(str[i]))
ans[i]='0';
else
ans[i]='1';
}
ans[i]='\0';
puts(ans);
}
return 0;
}
URAL 2040 Palindromes and Super Abilities 2(回文树)的更多相关文章
- Ural 2040. Palindromes and Super Abilities 2 回文自动机
2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...
- Ural 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged ...
- 回文树练习 Part1
URAL - 1960 Palindromes and Super Abilities 回文树水题,每次插入时统计数量即可. #include<bits/stdc++.h> using ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- 【CF245H】Queries for Number of Palindromes(回文树)
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
随机推荐
- NoSQL摘录
NoSQL泛指非关系型数据库,诸如Cassandra.MongoDB.Neo4J和Riak等.它们主张使用无模式(schemaless)的数据,可以运行在集群环境中. 开源的NoSQL数据库:Redi ...
- 关于UI功能解锁,UI特效动画,UI tips的再思考
之前写过一篇这样的文章,但当时的思路可行性太低 首先所有的UI面板通过发送字符串消息来告知,是否触发了解锁检测,tips检测,动画特效.可以理解为这样的接口: AsyncResult SendUIMe ...
- atitit.验证码识别step4--------图形二值化 灰度化
atitit.验证码识别step4--------图形二值化 灰度化 1. 常见二值化的方法原理总结 1 1.1. 方法一:该方法非常简单,对RGB彩色图像灰度化以后,扫描图像的每个像素值,值小于12 ...
- atitit.Sealink2000国际海运信息管理系统
atitit.Sealink2000国际海运信息管理系统 操作手册 目录 第一章 使用说明 第一节 系统登录 双击桌面的系统执行程序图标,进入选择数据库的对话框,如图1-1所示.选择相应的数据库后,点 ...
- VS中几个自动完成快捷键,还算实用
1,F2更换名字,自动完成 2.try switch等按两次TAB建,自动完成格式 3.自动属性快捷键 ctrl+r,ctrl+e 有人说是加个分号 就不需要写get set了.上下 ...
- jQuery中的text(),html(),val()有什么区别
text():获取或者改变指定元素的文本html():获取或改变指定元素的html元素以及文本val():获取或者改变指定元素的value值(一般是表单元素) 以上3个都是jquery类库中的语法 第 ...
- 在 Linux 客户端配置基于 Kerberos 身份验证的 NFS 服务器
在这篇文章中我们会介绍配置基于 Kerberos 身份验证的 NFS 共享的整个流程.假设你已经配置好了一个 NFS 服务器和一个客户端.如果还没有,可以参考 安装和配置 NFS 服务器[2] - 它 ...
- shader 笔记(一)
- spring boot +mybatis+druid 多数据源配置
因为我的工程需要在两个数据库中操作数据,所以要配置两个数据库,我这里没有数据源没有什么主从之分,只是配合多数据源必须要指定一个主数据源,所以我就把 操作相对要对的那个数据库设置为主数据(dataBas ...
- js上传控件 plupload 使用记录
最近一个项目需要使用一个上传控件进行多图片上传,给用户更好的体验,找到了plupload,用了一下感觉还是不错的, 1.从官网上 可以获得例子 ,我集成到了jsp,如下: <%@ page l ...