BZOJ3067 : Hyperdrome
设f[i][j]表示前i个字母中字母j出现的次数对2取模的结果。
若[l,r]经过重组可以形成回文串,则需满足f[l-1][j]与f[r][j]至多有1位不同。
将f[i]用一个long long表示,枚举不同的那一位,用Hash表支持查询即可。
时间复杂度$O(52n)$。
#include<cstdio>
#define M 8388607
typedef long long ll;
char ch;int n,i;ll x,y,ans;
struct E{ll x;int v;E*nxt;}*g[M+1],pool[300010],*cur=pool,*p;
inline void ins(ll x){
int i=x&M;
for(p=g[i];p;p=p->nxt)if(p->x==x){p->v++;return;}
p=cur++;p->x=x;p->v=1;p->nxt=g[i];g[i]=p;
}
inline int ask(ll x){
for(p=g[x&M];p;p=p->nxt)if(p->x==x)return p->v;
return 0;
}
int main(){
for(ins(0),scanf("%d",&n);n--;ins(y=x)){
while(!((((ch=getchar())>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z'))));
for(ans+=ask(x=y^(1LL<<(ch<='Z'?ch-'A':ch-'a'+26))),i=0;i<52;i++)ans+=ask(x^(1LL<<i));
}
return printf("%lld",ans),0;
}
BZOJ3067 : Hyperdrome的更多相关文章
- 2012-2013 ACM-ICPC Northeastern European Regional Contest (NEERC 12)
Problems # Name A Addictive Bubbles1 addictive.in / addictive.out 2 s, 256 MB x438 B Blin ...
- NEERC2012
NEERC2012 A - Addictive Bubbles 题目描述:有一个\(n \times m\)的棋盘,还有不同颜色的棋子若干个,每次可以消去一个同种颜色的联通块,得到的分数为联通块中的棋 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- 使用Unity创造动态的2D水体效果
者:Alex Rose 在本篇教程中,我们将使用简单的物理机制模拟一个动态的2D水体.我们将使用一个线性渲染器.网格渲染器,触发器以及粒子的混合体来创造这一水体效果,最终得到可运用于你下款游戏的水纹和 ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- nginx学习(二):初识配置文件
nginx的配置文件默认在nginx安装目录中的conf子目录中,主配置文件为nginx.conf, root@mgmserver conf]# pwd/usr/local/nginx/conf一.配 ...
- 【Markdown】notepad++ 支持 markdown语法、预览
Notepad++中支持Markdown 最近在学习Markdown语言的使用,很想在XP主机上使用Markdown的离线编辑器,但MarkdownPad.作业部分的离线客户端都不能再XP上运行, ...
- Python Elasticsearch api
描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下面介绍了利用Python API接口进行数据查询,方便 ...
- [Android Pro] 通过IMSI判断手机是移动、联通、电信
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); /** 获取 ...
- August 6th, 2016, Week 32nd, Saturday
It is not the mountain we conquer, but ourselvess. 我们征服的不是高山,而是我们自己. Difficulties and obstacles, jus ...
- Cookie的使用与实现记住用户名案例
学习web开发,使用Cookie是不可避免的,个人感觉Cookie的使用和ASP.NET中的Session非常像,只不过Cookie是保存在客户端,而Session是在服务器端,两者都以记录信息为目的 ...
- 谈JavaScript代码封装
前言 也算老生常谈的问题了,再深入搞一搞怎么玩儿封装,如果看到这篇文章的你,正好你也是追求完美的代码洁癖狂者,那么这篇文章相信非常适合你. 举一个例子,编写一个Person类,具有name和birth ...
- NGITOSS
https://sourceforge.net/projects/ngnms/files/?source=navbar http://stackoverflow.com/questions/17511 ...