Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new palindrome substrings appeared when he added that letter. Two substrings are considered distinct if they are different as strings. Which n numbers will be said by Misha if it is known that he is never wrong?

Input

The input contains a string s1 … sn consisting of letters ‘a’ and ‘b’ (1 ≤ n ≤ 5 000 000).

Output

Print n numbers without spaces: i-th number must be the number of palindrome substrings of the prefix s1 … si minus the number of palindrome substrings of the prefix s1 … si−1. The first number in the output should be one.

Sample

input output
abbbba
111111

Notes

We guarantee that jury has C++ solution which fits Time Limit at least two times. We do not guarantee that solution on other languages exists (even Java).
Problem Author: Mikhail Rubinchik (prepared by Kirill Borozdin)
Problem Source: Ural FU Dandelion contest. Petrozavodsk training camp. Summer 2014

题意:问从左向右,每次加入一个字符,新增加了多少个回文串(之前未出现过)。

思路:先用马拉车算法,得到每一个回文串的结束位置,以及对应的hash值(vector保存)。然后从左向右计算每个位置结束的hash值由多少是之前没有出现过的(map判重)。

Ural2040:Palindromes and Super Abilities(离线&manecher算法)的更多相关文章

  1. URAL 2040 Palindromes and Super Abilities 2 (回文自动机)

    Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...

  2. Ural 2040. Palindromes and Super Abilities 2 回文自动机

    2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...

  3. 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities

     Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...

  4. URAL 2040 Palindromes and Super Abilities 2(回文树)

    Palindromes and Super Abilities 2 Time Limit: 1MS   Memory Limit: 102400KB   64bit IO Format: %I64d ...

  5. Ural 1960 Palindromes and Super Abilities

    Palindromes and Super Abilities Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged ...

  6. URAL 2040 Palindromes and Super Abilities 2

    Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...

  7. URAL1960 Palindromes and Super Abilities

    After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...

  8. 【URAL】1960. Palindromes and Super Abilities

    http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...

  9. 回文树1960. Palindromes and Super Abilities

    Bryce1010模板 http://acm.timus.ru/problem.aspx?space=1&num=1960 #include <bits/stdc++.h> usi ...

随机推荐

  1. 【概率dp】D. Card Collector

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/D [题意] 为了集齐n张卡片,必须要买多少袋零食?题目给定每种卡片出现在零食中的 ...

  2. bzoj 3207 花神的嘲讽计划Ⅰ 主席树+hash

    花神的嘲讽计划Ⅰ Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3112  Solved: 1086[Submit][Status][Discuss] ...

  3. 尽量写出大家都能看懂的ReactJS入门教程

    个人感觉ReactJS相比于传统的JS框架还是挺有意思的,主要是它将JS代码和HTML代码完美的结合在了一起,有点jsp把java代码和html混在一起写的意思?但是它通过组件的形式实现了代码可复用, ...

  4. 2016 年末 QBXT 入学测试

    P4744 A’s problem(a) 时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试题,每三天结算一次成绩.参与享优惠 描述 这是一道有背 ...

  5. hdu6110:路径交

    $n \leq 500000$的树给$m \leq 500000$个路径,$q \leq 500000$个询问每次问一个区间的路径交. 路径交口诀:(前方高能) 判有交,此链有彼祖: 取其交,最深两两 ...

  6. Linux后台运行命令nohub输出pid到文件(转)

    用nohup可以启动一个后台进程.让一个占用前台的程序在后台运行,并静默输出日志到文件: nohup command > logfile.txt & 但是如果需要结束这个进程,一般做法是 ...

  7. 拷贝地图 CopyAndOverwriteMap()

    private void CopyAndOverwriteMap() { //Get IObjectCopy interface IObjectCopy objectCopy = new Object ...

  8. 【Todo】秒杀系统 & 乐观锁 & Nginx反向代理

    http://www.csdn.net/article/2014-11-28/2822858 1. 单点帐号验证,不用读,而是用写入,Redis,看是否加watch 2. 抢宝的最终购买冲突.包装称“ ...

  9. Fragment实践之聊天窗体

    前几天刚学了android的fragment,总是停留在简单的demo,也许永远都学不会. 今天,我要动手向我的聊天软件开刀.今天.用Fragment来实现一个例如以下图效果的聊天界面. waterm ...

  10. Linux内核project导论——网络:Filter(LSF、BPF、eBPF)

    概览 LSF(Linux socket filter)起源于BPF(Berkeley Packet Filter).基础从架构一致.但使用更简单.LSF内部的BPF最早是cBPF(classic).后 ...