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傻逼题 只是用回文树写写而已.. ...
随机推荐
- word2vector 理解入门
1.什么是word2vector? 我们先来看一个问题,假如有一个句子 " the dog bark at the mailman". 假如用向量来表示每个单词,我们最先想到的是用 ...
- Lintcode---单词的添加与查找
设计一个包含下面两个操作的数据结构:addWord(word), search(word) addWord(word)会在数据结构中添加一个单词.而search(word)则支持普通的单词查询或是只包 ...
- C#颜色 Color.FromArgb ColorTranslator 16进制
//方法1: //引用命名空间 using System.Drawing; 16进制颜色代码转Color类型:ColorTranslator.FromHtml(color); Color类型转16进制 ...
- 代码覆盖率?coverage
http://www.infoq.com/cn/articles/test-coverage-rate-role 代码覆盖率?coverage http://www.cnblogs.com/cod ...
- Makefile 自动变量之 $(@D),$(@F)
参考:http://www.gnu.org/software/make/manual/make.html '$(@D)'The directory part of the file name of t ...
- JS的类型转换,强制转换和隐式转换
JS的类型转换 1.强制转换 通过String(),Number(),Boolean()函数强制转换 var str=123; var str1='123'; console.log(typeof s ...
- Windows自带的端口转发工具netsh使用方法
微软Windows的netsh是一个命令行脚本实用工具.使用netsh工具 ,可以查看或更改本地计算机或远程计算机的网络配置.不仅可以在本地计算机上运行这些命令,而且可以在网络上的远程计算机上运行. ...
- STM32F10x_硬件I2C读写EEPROM(标准外设库版本)
Ⅰ.写在前面 上一篇文章是“STM32F10x_模拟I2C读写EEPROM”,讲述使用IO口模拟I2C总线通信,对EEPROM(AT24Xxx)进行读写操作的过程. 上一篇文章主要内容:I2C协议.模 ...
- 页面中添加qq客服
html页面 <html> <head> <meta http-equiv="Content-Type" content="text/htm ...
- liunx下安装mysql(未完待更新)
1.下载mysql-liunx 下载地址:http://download.csdn.net/download/yichen01010/10019139 2.删除系统自带mysql rpm -qa|gr ...