用常用的套路,排序之后从大到小插入height,用并查集维护即可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=;
const ll inf=1e18;
int n,sa[maxn],H[maxn],ra[maxn],tong[maxn],m,tp[maxn],fa[maxn];
ll ans1[maxn],ans2[maxn],c[maxn];
char s[maxn];
int getfa(int x){return (x==fa[x])?x:fa[x]=getfa(fa[x]);}
void rsort(){
for(int i=;i<=m;++i)tong[i]=;
for(int i=;i<=n;++i)tong[ra[tp[i]]]++;
for(int i=;i<=m;++i)tong[i]+=tong[i-];
for(int i=n;i>=;--i)sa[tong[ra[tp[i]]]--]=tp[i];
}
int cmp(int x,int y,int w){return tp[x]==tp[y]&&tp[x+w]==tp[y+w];}
void pre(){
for(int i=;i<=n;++i)ra[i]=s[i]-'a'+,tp[i]=i; m=;rsort(); for(int w=,p=,i;p<n;w+=w,m=p){
for(p=,i=n-w+;i<=n;++i)tp[++p]=i;
for(i=;i<=n;++i)if(sa[i]>w)tp[++p]=sa[i]-w;
rsort();swap(tp,ra);ra[sa[]]=p=;
for(i=;i<=n;++i)ra[sa[i]]=cmp(sa[i],sa[i-],w)?p:++p;
}
int j,k=;
for(int i=;i<=n;H[ra[i++]]=k)
for(k=k?k-:k,j=sa[ra[i]-];s[i+k]==s[j+k];++k);
}
struct node{
int id,v;
bool operator<(const node&t)const{
return v<t.v;
}
}tmp[maxn];
struct lian{
int l,r;
ll ma,mi,len;
}a[maxn];
void merge(int x,int y,int w){
x=getfa(x);y=getfa(y);
ll t1=max(a[x].ma*a[y].ma,a[x].mi*a[y].mi);
ll t2=max(a[x].ma*a[y].mi,a[x].mi*a[y].ma);
ll t3=min(a[x].ma*a[y].ma,a[x].mi*a[y].mi);
ll t4=min(a[x].ma*a[y].mi,a[x].mi*a[y].ma);
a[x].ma=max(a[x].ma,a[y].ma);
a[x].mi=min(a[y].mi,a[x].mi);
ans1[w]+=a[x].len*a[y].len;
a[x].len+=a[y].len;
fa[y]=x;
ans2[w]=max(ans2[w],max(t1,t2)); }
int main(){
cin>>n;
scanf("%s",s+);
pre();
for(int i=;i<=n;++i){
tmp[i-].id=i,tmp[i-].v=H[i];
}
sort(tmp+,tmp+n);
for(int i=;i<=n;++i)scanf("%lld",&c[i]);
for(int i=;i<=n;++i){
a[i].mi=a[i].ma=c[sa[i]];
a[i].l=a[i].r=i;a[i].len=;
fa[i]=i;
}
//for(int i=1;i<=n;++i)cout<<sa[i]<<' '<<H[i]<<endl;
for(int i=;i<=n;++i)ans2[i]=-inf;
for(int i=n-;i>=;--i){
merge(tmp[i].id-,tmp[i].id,tmp[i].v);
}
for(int i=n-;i>=;--i){
ans1[i]+=ans1[i+];
ans2[i]=max(ans2[i],ans2[i+]);
}
for(int i=;i<=n-;++i){
printf("%lld ",ans1[i]);
if(ans2[i]==-inf)printf("%lld\n",);
else printf("%lld\n",ans2[i]);
}
return ;
}

noi2015品酒大会(sa)的更多相关文章

  1. [NOI2015]品酒大会(SA数组)

    [NOI2015]品酒大会 题目描述 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战 两个环节,分别向优胜者颁发"首席品酒家"和" ...

  2. Luogu2178 NOI2015 品酒大会 SA、并查集

    传送门 感觉题目讲的很不清楚-- 题目意思就是给出一个长度为\(n\)的字符串,求对于\(r=0,1,...,n-1\),求出\(LCP(suffix_p,suffix_q) \geq r\)的无序数 ...

  3. BZOJ 4199: [Noi2015]品酒大会 [后缀数组 带权并查集]

    4199: [Noi2015]品酒大会 UOJ:http://uoj.ac/problem/131 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 ...

  4. [UOJ#131][BZOJ4199][NOI2015]品酒大会 后缀数组 + 并查集

    [UOJ#131][BZOJ4199][NOI2015]品酒大会 试题描述 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品酒家”和“首席猎手”两个 ...

  5. 洛谷 P2178 [NOI2015]品酒大会 解题报告

    P2178 [NOI2015]品酒大会 题目描述 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战 两个环节,分别向优胜者颁发"首席品酒家"和 ...

  6. 【BZOJ4199】[Noi2015]品酒大会 后缀数组+并查集

    [BZOJ4199][Noi2015]品酒大会 题面:http://www.lydsy.com/JudgeOnline/wttl/thread.php?tid=2144 题解:听说能用SAM?SA默默 ...

  7. [UOJ#131][BZOJ4199][NOI2015]品酒大会

    [UOJ#131][BZOJ4199][NOI2015]品酒大会 试题描述 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品酒家”和“首席猎手”两个 ...

  8. [NOI2015] 品酒大会 - 后缀数组,并查集,STL,启发式合并

    [NOI2015] 品酒大会 Description 对于每一个 \(i \in [0,n)\) 求有多少对后缀满足 LCP 长度 \(\le i\) ,并求满足条件的两个后缀权值乘积的最大值. So ...

  9. BZOJ_4199_[Noi2015]品酒大会_后缀自动机

    BZOJ_4199_[Noi2015]品酒大会_后缀自动机 Description 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 酒家”和“首席 ...

  10. 洛谷P2178 [NOI2015]品酒大会 后缀数组+单调栈

    P2178 [NOI2015]品酒大会 题目链接 https://www.luogu.org/problemnew/show/P2178 题目描述 一年一度的"幻影阁夏日品酒大会" ...

随机推荐

  1. Python:笔记1_字符串处理【转载】

    [转载自:https://www.cnblogs.com/houht/p/3308634.html] 1. 判断字符串str是否为空Approach 1:如果字符串长度为0,说明字符串为空,code如 ...

  2. 学习笔记:ECharts

    (Highcharts 167K:  ECharts 354K: jqChart 240K),如果用于网络,Highchart最小 ECharts (Enterprise Charts 商业产品图表库 ...

  3. hive 表锁和解锁

    场景: 在执行insert into或insert overwrite任务时,中途手动将程序停掉,会出现卡死情况(无法提交MapReduce),只能执行查询操作,而drop insert操作均不可操作 ...

  4. mybatis的Selective接口和普通接口的区别

    举例说明: updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法. updateByPrimaryKey对你 ...

  5. ElasicSearch(3) 安装elasticsearch-head

    https://github.com/mobz/elasticsearch-head 1.git install git 2.git clone git://github.com/mobz/elast ...

  6. saltstack的封装和内网使用

    0.客户端使用 linux:把linux的ragent文件夹拷贝到内网linux /opt目录下,运行初始化脚本 salt服务端:# @Master:"/opt/ragent/python/ ...

  7. java学习--java源文件

    java源文件以“java”为扩展名.源文件的基本组成部分是类(class) 一个源文件中最多只能有一个public类.其他类(如抽象类,default类即省去修饰符的类,接口)的个数不限. 如果源文 ...

  8. Delphi TXLSReadWriteII导出Excel

    TXLSReadWriteII导出Excle (有点复杂,可以自己简化一下,直接从项目中抓取的) procedure TformSubReport.DataToExcel(_Item: Integer ...

  9. TXLSReadWriteII 公式计算

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  10. centos6安装rabbitmq

    一.安装依赖包 yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ k ...