标签:imu printf stream using int class har define tor
待补。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
#define RG register int
#define LL long long
const LL MOD=1000000007LL;
LL Mul[1000010];
int Pos[1000010];
char str[1000010];
int T,N;
void Lyndon(char *s,int len){
int i=1,j,k;
while(i<=len){
Pos[i]=i;
for(j=i,k=i+1;k<=len && s[j]<=s[k];++k){
if(j==i) Pos[k-1]=i;
else Pos[k-1]=Pos[j-1]+k-j;
if(s[j]<s[k]) j=i;
else ++j;
}
while(i<=j){Pos[i+k-j-1]=i;i+=k-j;}
}
return;
}
int main(){
Mul[0]=1;
for(RG i=1;i<=1000000;++i)
Mul[i]=Mul[i-1]*1112LL%MOD;
scanf("%d",&T);
while(T--){
scanf("%s",str+1);
N=strlen(str+1);
Lyndon(str,N);
LL Ans=0;
for(RG i=1;i<=N;++i)
Ans=(Ans+(LL)Pos[i]*Mul[i-1]%MOD)%MOD;
printf("%lld\n",Ans);
}
return 0;
}
[Lyndon分解] HDU 6761 Minimum Index (2020多校训练)
标签:imu printf stream using int class har define tor
原文地址:https://www.cnblogs.com/AEMShana/p/13358233.html