技术笔记:SCU4484

简介: 技术笔记:SCU4484

The Graver Robbers' Chronicles


Description


One day, Kylin Zhang and Wu Xie are trapped in a graveyard. They find an ancient piece of parchment with a cipher string.


After discussion and analysis, they find the password is the total number of the cipher string's distinct substrings.


Although Kylin Zhang is powerful and always help his friends get rid of danger, this time he is helpless beacause


he is not good at math and programming.


As a smart Acmer, can you help them solve this problem so that they can escape from this horrible graveyard.


Input


The first line is an integer T stands for the number of test cases.


Then T test case follow.


For each test case there is one string.


Constraints:


T is no bigger than 30.


The length of string is no bigger than 50000.


Every string only contains lowercase letters.


Output


For each test case, output the answer in a single line. one number saying the number of distinct substrings.


Sample Input


2


aaaaa


cacac


Sample Output


5


9


Hint


For test case 2, the distinct substrings of 'cacac' are as follows:


len = 1 : c , a


len = 2 : ca , ac


len = 3 : cac , aca


len = 4 : caca , acac


len = 5 : cacac


Thus, total number of distinct substrings is 9.


分析:字符串的处理问题,查重的时候使用后缀数组就可以了。


算出总的子串 len(len+1)/2


再减去重复的 Height(i)


即可


套用了一下 大大的后缀数组模板,地址:


代码如下:


#include


#include


#include


#define LL long long


#define ULL unsigned long long


using namespace std;


const int MAXN=100010;


//以下为倍增算法求后缀数组


int wa【MAXN】,wb【MAXN】,wv【MAXN】,Ws【MAXN】;


int cmp(int //代码效果参考:http://www.lyjsj.net.cn/wz/art_23208.html

r,int a,int b,int l)

{return r【a】==r【b】&&r【a+l】==r【b+l】;}


/< 传入参数:str,sa,len+1,ASCII_MAX+1 /


void da(const char r【】,int sa【】,int n,int m)


{


int i,j,p,x=wa,y=wb,t;


for(i=0; i

for(i=0; i

for(i=1; i

for(i=n-1; i>=0; i--) sa【--Ws【x【i】】】=i;


/cout["SA"[endl;;


for(int i=0;i<n+1;i++)cout[sa【i】[' ';/


for(j=1,p=1; p

{


for(p=0,i=n-j; i

for(i=0; i=j) y【p++】=sa【i】-j;


for(i=0; i

for(i=0; i

for(i=0; i

//代码效果参考:http://www.lyjsj.net.cn/wz/art_23206.html

for(i=1; i

for(i=n-1; i>=0; i--) sa【--Ws【wv【i】】】=y【i】;


for(t=x,x=y,y=t,p=1,x【sa【0】】=0,i=1; i

x【sa【i】】=cmp(y,sa【i-1】,sa【i】,j)?p-1:p++;


}


return;


}


int sa【MAXN】,Rank【MAXN】,height【MAXN】;


//求height数组


/< str,sa,len /


void calheight(const char r,int sa,int n)


{


int i,j,k=0;


for(i=1; i<=n; i++) Rank【sa【i】】=i;


for(i=0; i

for(k?k--:0,j=sa【Rank【i】-1】; r【i+k】==r【j+k】; k++);


// Unified


for(int i=n;i>=1;--i) ++sa【i】,Rank【i】=Rank【i-1】;


}


int main()


{


char r【MAXN】;


int m,n,t;


LL H,ans;


cint;


while(t--)


{


cinr;


n=strlen(r);


m=127;


da(r,sa,n+1,m+1);


calheight(r,sa,n);


H=n;


ans=(H+1)H/2;


for(int i=2;i<=n;i++)


{


ans-=height【i】;


}


cout[ans[endl;


}


}

相关文章
|
2月前
|
存储 固态存储 大数据
阿里云服务器各收费项目最新收费标准与活动报价参考
阿里云服务器收费项目有实例价格、预留实例券、专有宿主机、块存储价格、存储容量单位包、带宽价格和快照服务价格,收费模式有包年包月和按量付费模式。2024年,阿里云继续推出各种云服务器的优惠,其中轻量应用服务器最低61元/1年,经济型e实例云服务器最低99元/1年,2核4G轻量应用服务器165元/1年,4核8G配置云服务器按量付费带宽模式最低299元/1年。本文为大家汇总了2024年阿里云服务器各个收费项目的最新收费标准与云服务器的最新活动报价,以供参考和了解。
阿里云服务器各收费项目最新收费标准与活动报价参考
|
20天前
|
弹性计算
2024年阿里云免费云服务器及学生三百通用额度申请教程参考
阿里云2024年继续提供免费学生云服务器,最长可享7个月(1+6个月);还有300元无门槛抵用金,适用于全量公共云产品(特殊商品除外)。学生需完成身份认证和任务以领取和续费。此外,有3个月免费的飞天试用云服务器,分为个人和企业版。详细申请教程包括学生认证、试用产品选择等步骤,可访问指定阿里云链接进行操作。
1144 2
|
2月前
|
弹性计算 运维 负载均衡
阿里云轻量应用服务器产品简介、收费标准与活动价格、搭建个人博客教程参考
阿里云轻量应用服务器是深受个人和普通企业用户亲耐的一款轻量级云服务器产品,提供精品应用一键部署,支持一站式的域名、网站、安全、运维、应用管理等服务,极大优化搭建简单应用的体验,降低了入门级用户使用云计算产品的门槛。本文来介绍全方位介绍一下阿里云轻量应用服务器的产品知识,以及最新的收费标准与活动价格情况,另外再奉上使用轻量应用服务器搭建个人博客的建站教程,以供参考。
阿里云轻量应用服务器产品简介、收费标准与活动价格、搭建个人博客教程参考
|
2月前
|
弹性计算 小程序 测试技术
带你读《弹性计算技术指导及场景应用》——3. ECS部署2048小游戏
带你读《弹性计算技术指导及场景应用》——3. ECS部署2048小游戏
585 1
|
11月前
|
弹性计算 固态存储 数据可视化
阿里云服务器最新新收费标准及优惠价格参考(2023调价)
阿里云服务器最新新收费标准及优惠价格参考(2023调价)2023年阿里云服务器租用费用,轻量应用服务器和云服务器ECS优惠价格表,阿里云轻量应用服务器2核2G3M带宽轻量服务器一年108元,2核4G4M带宽轻量服务器一年297.98元12个月,云服务器ECS包括通用算力型u1、ECS计算型c7、通用型g7和内存型r7均有活动
217 0
|
存储 弹性计算 安全
阿里云4核16G配置云服务器收费标准及新老用户优惠价格整理与参考
阿里云服务器4核16G配置支持按量(小时)付费和按月付费及按年付费,根据小编查询的结果,目前按量付费收费标准最低0.8元每小时,按月收费最低收费标准为384.0元1个月,实际购买中,新老用户均可通过阿里云活动下单购买,新用户最低优惠价格为1710.00元1年,老用户最低优惠价格为3489.00元1年,下文是阿里云服务器4核16G配置最新收费标准及新老用户优惠价格。
744 0
阿里云4核16G配置云服务器收费标准及新老用户优惠价格整理与参考
|
存储 弹性计算 安全
阿里云服务器4核8G配置收费标准及新老用户优惠价格整理与参考
阿里云服务器4核8G配置支持按量(小时)付费和按月付费及按年付费,按量付费收费标准最低0.533866元每小时,按月收费最低收费标准为231.0元1个月,实际购买中,新老用户均可通过阿里云的各个活动下单购买,新用户最低优惠价格为1367.86元1年,老用户最低优惠价格为2804.71元1年,下文是阿里云服务器4核8G配置最新收费标准及新老用户优惠价格。
580 0
阿里云服务器4核8G配置收费标准及新老用户优惠价格整理与参考
|
12月前
|
弹性计算 固态存储 数据可视化
阿里云服务器最新新收费标准及优惠价格参考(2023年调价)
阿里云服务器最新新收费标准及优惠价格参考(2023年调价)
|
弹性计算 大数据 测试技术
2023年最新阿里云服务器价格表出炉(精准配置收费标准)
2023年最新阿里云服务器价格表出炉(精准配置收费标准)轻量应用服务器和云服务器ECS优惠价格表,阿里云轻量应用服务器2核2G3M带宽轻量服务器一年108元,2核4G4M带宽轻量服务器一年297.98元12个月,云服务器ECS包括通用算力型u1、ECS计算型c7、通用型g7和内存型r7均有活动
1008 0
|
弹性计算 固态存储 数据可视化
2023年最新阿里云服务器价格表出炉(精准收费标准)
2023年最新阿里云服务器价格表出炉(精准收费标准)轻量应用服务器和云服务器ECS优惠价格表,阿里云轻量应用服务器2核2G3M带宽轻量服务器一年108元,2核4G4M带宽轻量服务器一年297.98元12个月,云服务器ECS包括通用算力型u1、ECS计算型c7、通用型g7和内存型r7均有活动
1020 0