【BZOJ2081】Beads(哈希表)
题意:

翻转是指其中一段长度为k的子串全部翻转
n<=200000 a[i]<=n
思路:枚举k,直接哈希判充即可
时间复杂度是n/i求和,根据定理可得是O(n log n)级别的
单哈双哈都可能被卡,我用的是单哈+哈希表判重
const mo=;
var h1,h2,mi,c,a,head,vet,next:array[..]of longint;
n,i,p,j,st,ed,t1,t2,t3,l,ans,tot:longint; function hash1(x,y:longint):longint;
begin
hash1:=(h1[y]-int64(h1[x-])*mi[y-x+] mod mo) mod mo;
hash1:=(hash1+mo) mod mo;
end; function hash2(x,y:longint):longint;
begin
hash2:=(h2[y]-int64(h2[x-])*mi[y-x+] mod mo) mod mo;
hash2:=(hash2+mo) mod mo;
end; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; procedure add(a,b:longint);
begin
inc(tot);
next[tot]:=head[a];
vet[tot]:=b;
head[a]:=tot;
end; function judge(u,x:longint):boolean;
var e,v:longint;
begin
e:=head[u];
while e<> do
begin
v:=vet[e];
if v=x then exit(false);
e:=next[e];
end;
exit(true);
end; begin
assign(input,'bzoj2081.in'); reset(input);
assign(output,'bzoj2081.out'); rewrite(output);
readln(n);
for i:= to n do read(a[i]);
mi[]:=;
for i:= to n do mi[i]:=int64(mi[i-])* mod mo;
for i:= to n do h1[i]:=(int64(h1[i-])*+a[i]) mod mo;
for i:= to n div do swap(a[i],a[n-i+]);
for i:= to n do h2[i]:=(int64(h2[i-])*+a[i]) mod mo;
for i:= to n do
begin
p:=; tot:=;
for j:= to n div i do
begin
st:=i*(j-)+; ed:=i*j;
t1:=hash1(st,ed); t2:=hash2(n-ed+,n-st+);
t3:=int64(t1)*t2 mod mo;
inc(t3); inc(t1); inc(t2);
if judge(t3,t1) then
begin
inc(p);
add(t3,t1);
add(t3,t2);
end;
end;
if p=ans then begin inc(l); c[l]:=i; end;
if p>ans then
begin
l:=; c[]:=i; ans:=p;
end;
for j:= to n div i do
begin
st:=i*(j-)+; ed:=i*j;
t1:=hash1(st,ed); t2:=hash2(n-ed+,n-st+);
t3:=int64(t1)*t2 mod mo;
inc(t3);
head[t3]:=;
end;
end;
writeln(ans,' ',l);
for i:= to l- do write(c[i],' ');
write(c[l]);
close(input);
close(output);
end.
【BZOJ2081】Beads(哈希表)的更多相关文章
- [PHP内核探索]PHP中的哈希表
在PHP内核中,其中一个很重要的数据结构就是HashTable.我们常用的数组,在内核中就是用HashTable来实现.那么,PHP的HashTable是怎么实现的呢?最近在看HashTable的数据 ...
- Java 哈希表运用-LeetCode 1 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- ELF Format 笔记(十五)—— 符号哈希表
ilocker:关注 Android 安全(新手) QQ: 2597294287 符号哈希表用于支援符号表的访问,能够提高符号搜索速度. 下表用于解释该哈希表的组织,但该格式并不属于 ELF 规范. ...
- Java基础知识笔记(一:修饰词、向量、哈希表)
一.Java语言的特点(养成经常查看Java在线帮助文档的习惯) (1)简单性:Java语言是在C和C++计算机语言的基础上进行简化和改进的一种新型计算机语言.它去掉了C和C++最难正确应用的指针和最 ...
- 什么叫哈希表(Hash Table)
散列表(也叫哈希表),是根据关键码值直接进行访问的数据结构,也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个映射函数叫做散列函数,存放记录的数组叫做散列表. - 数据结构 ...
- 【哈希表】CodeVs1230元素查找
一.写在前面 哈希表(Hash Table),又称散列表,是一种可以快速处理插入和查询操作的数据结构.哈希表体现着函数映射的思想,它将数据与其存储位置通过某种函数联系起来,其在查询时的高效性也体现在这 ...
- openssl lhash 数据结构哈希表
哈希表是一种数据结构,通过在记录的存储位置和它的关键字之间建立确定的对应关系,来快速查询表中的数据: openssl lhash.h 为我们提供了哈希表OPENSSL_LHASH 的相关接口,我们可以 ...
- Berkeley DB的数据存储结构——哈希表(Hash Table)、B树(BTree)、队列(Queue)、记录号(Recno)
Berkeley DB的数据存储结构 BDB支持四种数据存储结构及相应算法,官方称为访问方法(Access Method),分别是哈希表(Hash Table).B树(BTree).队列(Queue) ...
- python数据结构与算法——哈希表
哈希表 学习笔记 参考翻译自:<复杂性思考> 及对应的online版本:http://greenteapress.com/complexity/html/thinkcomplexity00 ...
随机推荐
- (博弈论)51NOD 1069 Nim游戏
有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N及每堆石子的数量,问最后 ...
- Rabbitmq笔记一
几个基本概念 Producer 生产者,发送消息的一方,图中左侧的client. Consumer 消费者,接收消息的一方,图中后侧的client. Broker 消息中间件的服务节点,一般一个Rab ...
- redis 缓存应用
第1章 部署与安装 wget http://download.redis.io/releases/redis-3.2.10.tar.gz tar xf redis-3.2.10.tar.gz cd r ...
- PWBI--Excel 数据源
博客园地址: http://blog.sina.com.cn/s/blog_68c4467d0102w5cc.html http://www.cnblogs.com/asxinyu/p/Power_B ...
- ACM_N皇后问题
N皇后问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不 ...
- Unity笔记(3)自学第二天
学习记录: 界面使用: 脚本使用: 脚本注意点:
- Errors reported here must be corrected before the service can be started
场景: 安装.配置Apache24时候,最后会给出提示,如图:Errors reported here must be corrected before the service can be star ...
- 字符流-缓冲区-自定义myBufferedReader
public class myBufferedReaderDemo { public static void main(String[] arg) throws IOException{ FileRe ...
- cstring 转string
(1)CString转换为string CString cs(_T("cs")); string s; s = (LPCSTR)(CStringA)(cs); (2)string转 ...
- VMware vCenter 6.5 安装及群集配置介绍
一.介绍 VMware vCenter Server 提供了一个可伸缩.可扩展的平台,为虚拟化管理奠定了基础.可集中管理VMware vSphere环境,与其他管理平台相比,极大地提高了 IT 管理员 ...