题目大意:
  给定一个长度为$n(n\leq200000)$的串$S_{1\sim n}$,选择一个$l$,从$S_1$开始,将$S$分为连续的若干段,使得每一段长度为$l$。令$k$为分出来不同的子串个数(翻转后相同算作相同),求最大的$k$,以及有哪些$l$对应的答案为$k$。

思路:
  枚举长度,求正反两个哈希去重。

 #include<set>
#include<cstdio>
#include<cctype>
#include<vector>
typedef unsigned long long uint64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,BASE=;
int a[N];
uint64 pow[N],h1[N],h2[N];
std::set<uint64> set;
std::vector<int> v;
inline uint64 hash1(const int &l,const int &r) {
return h1[r]-h1[l-]*pow[r-l+];
}
inline uint64 hash2(const int &l,const int &r) {
return h2[l]-h2[r+]*pow[r-l+];
}
int main() {
const int n=getint();
for(register int i=;i<=n;i++) a[i]=getint();
for(register int i=;i<=n;i++) h1[i]=h1[i-]*BASE+a[i];
for(register int i=n;i>=;i--) h2[i]=h2[i+]*BASE+a[i];
for(register int i=pow[]=;i<=n;i++) pow[i]=pow[i-]*BASE;
int ans=;
for(register int i=;ans*i<=n;i++) {
set.clear();
int tmp=;
for(register int j=;i+j-<=n;j+=i) {
const int h1=hash1(j,j+i-),h2=hash2(j,j+i-);
if(!set.count(h1)||!set.count(h2)) {
set.insert(h1),set.insert(h2);
tmp++;
}
}
if(tmp>ans) {
ans=tmp;
v.clear();
}
if(tmp==ans) v.push_back(i);
}
printf("%d %lu\n",ans,v.size());
for(register unsigned i=;i<v.size();i++) {
printf("%d%c",v[i]," \n"[i==v.size()-]);
}
return ;
}

[POI2010]Beads的更多相关文章

  1. bzoj 2081 [Poi2010]Beads hash+调和级数

    2081: [Poi2010]Beads Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1003  Solved: 334[Submit][Statu ...

  2. 【BZOJ2081】[Poi2010]Beads hash+调和级数

    [BZOJ2081][Poi2010]Beads Description Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串), ...

  3. BZOJ 2081: [Poi2010]Beads

    Description 问把n截成每个长度后不同子串个数. Sol 调和极数+Hash. 首先这是一个式子 \(n\sum_{i=1}^n \frac {1}{i}\) . 这东西就是调和极数再乘上 ...

  4. BZOJ2081 : [Poi2010]Beads

    暴力枚举$k$,对于一个子串,计算它正着的hash值以及反着的hash值,取最小值得到其最终hash值. 对于$k$,一共有$\lfloor\frac{n}{k}\rfloor$个子串,计算出它们的最 ...

  5. 【bzoj2081】[Poi2010]Beads Hash

    题目描述 Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不是k的倍数, ...

  6. POI2010题解

    POI2010题解 我也不知道我为什么就开始刷POI了 有些题目咕掉了所以不完整(我都不知道POI到底有多少题) [BZOJ2079][Poi2010]Guilds (貌似bz跟洛谷上的不是一个题?) ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. LOJ#2427. 「POI2010」珍珠项链 Beads

    题目地址 题目链接 题解 不会算复杂度真是致命,暴力枚举k每次计算是n/2+n/3+n/4+...+1的,用调和级数算是\(O(nlogn)\)的... 如果写哈希表的话能够\(O(nlogn)\), ...

  9. Beads

    Beads 题目描述 Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不 ...

随机推荐

  1. Day3 UI:7种常用控件、4种基本布局

    Android常用控件 TextView <TextView android:id="@+id/text_view" android:layout_width="m ...

  2. HDU 3775 Chain Code pick定理

    pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积. 思路:http://blog.csdn.net ...

  3. ESLint 代码检查规范

    目录 Airbnb Javascript Style Guide 引用 对象 数组 函数 箭头函数 类和构造器 模块 Iterators and Generators 变量 比较运算符 注释 空格 A ...

  4. 201621123034 《Java程序设计》第11周学习总结

    作业11-多线程 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread ...

  5. PAT 1050 螺旋矩阵

    https://pintia.cn/problem-sets/994805260223102976/problems/994805275146436608 本题要求将给定的 N 个正整数按非递增的顺序 ...

  6. hadoop2.6.4【windows7】构建maven项目 系列2

    准备windows版本的hadoop2.6.4 下载windows版本的hadoop2.6.4解压在本地 新建maven项目构建hadoop依赖 <?xml version="1.0& ...

  7. VMware ESXI 5.5 注册码

    VMware ESXI 5.5 注册码 ESXI 注册码0A42V-8M182-3ZZ88-R21N6-32K5H ESXi Server许可证类型产品: Mware vSphere 5 Enterp ...

  8. 2013年 ACMICPC 杭州赛区H题

    思路:树状数组统计.待验证,不知道是否对. #include<cstdio> #include<cstring> #include<cmath> #include& ...

  9. 阿里云服务器ubuntu安装java运行环境

    服务器 阿里云服务器ubuntu安装java运行环境 转:http://www.codingyun.com/article/45.html 今天来给大家介绍一下在阿里云ubuntu服务器下安装java ...

  10. Spring整合hibernate4:事务管理

    Spring整合hibernate4:事务管理 Spring和Hibernate整合后,通过Hibernate API进行数据库操作时发现每次都要opensession,close,beginTran ...