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傻逼题 只是用回文树写写而已.. ...
随机推荐
- JavaNIO - AbstractInterruptibleChannel
1. 描述 可异步关闭和中断的Channel. (1)实现InterruptibleChannel接口的Channel支持异步关闭:如果一个线程IO阻塞在一个可中断的channel,另一个线程可以执行 ...
- 学习笔记:iOS 视图控制器(UIViewController)剖析
转自:http://www.cnblogs.com/martin1009/archive/2012/06/01/2531136.html 视图控制器在iOS编程中占据非常重要的位置,因此我们一定要掌握 ...
- nginx rewrite location 内置全局变量
$args :这个变量等于请求行中的参数,同$query_string $content_length : 请求头中的Content-length字段. $content_type : 请求头中的Co ...
- git 删除github上的文件
硬盘删除文件后,执行$ git status 会提示你仍然需要$ git rm <文件> 此时如果是要删除大批量文件,这么一个一个命令下去不得累死人啊 其实可以这样(不管之前有 ...
- jdk8 Function
例子 1: // 定义function Function<String, String> fun = parm -> { // 这里是定function中的逻辑 return Str ...
- 15.3.14 DP练习2
拦截导弹 题目 某国为了防御敌国的导弹突击,发展出一种导弹拦截系统. 可是这样的导弹拦截系统有一个缺陷:尽管它的第一发炮弹可以到达随意的高度.可是以后每一发炮弹都不能高于前一发的高度. 某天,雷达捕捉 ...
- 在drop user之前,建议获取该用户的依赖情况
在删除这两个用户之前,建议获取这两个用户的依赖情况: SQL> col owner format a15 SQL> col name format a15 SQL> col REFE ...
- Android 开发 -------- 自己定义View 画 五子棋
自己定义View 实现 五子棋 配图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG92ZV9KYXZjX3lvdQ==/font/5a6L5L2T ...
- hdu6059 Kanade's trio 字典树+容斥
转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...
- 编写可维护的JavaScript----笔记(三)
1.块语句花括号的使用 在JavaScript中,注入if和for语句有两种写法,使用花括号包裹的多行代码或者不使用花括号的单行代码.但强烈建议不论是单行还是多行代码,都应该使用花括号. 2.花括号的 ...