UVALive 6711(2013长春区域赛)

Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only
if
(i) It is of length M ∗ L;
(ii) It can be constructed by concatenating M “diversified” substrings of S, where each of these
substrings has length L; two strings are considered as “diversified” if they don’t have the same
character for every position.
Two substrings of S are considered as “different” if they are cut from different part of S. For
example, string “aa” has 3 different substrings “aa”, “a” and “a”.
Your task is to calculate the number of different “recoverable” substrings of S.
Input
The input contains multiple test cases, proceeding to the End of File.
The first line of each test case has two space-separated integers M and L.
The second ine of each test case has a string S, which consists of only lowercase letters.
The length of S is not larger than 105
, and 1 ≤ M ∗ L ≤ the length of S.
Output
For each test case, output the answer in a single line.
Sample Input
3 3
abcabcbcaabc
Sample Output
2

这题的正解应该是字符串HASH,我只想到了用后缀数组来实现

题目是要求找出一个M*L的子串,要求该子串中至少有两个长度的L的字符串不相同,问有多少种这种子串

先用后缀数组处理出所有后缀,我们可以先找相同的L长度的子串,这样对后缀数组for一遍即可标记处所有不满足的字符串,这个过程可以结合线段树查询来完成(我总觉得这么写多此一举,但当时又没想到好的方法,代码量多了好多),最后用所有的方案数减去不满足的数量即可

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          using namespace std; #define maxn 101000 #define lson l,m,o<<1 #define rson m+1,r,o<<1|1 char s[maxn]; int sa[maxn]; int ra[maxn]; int c[maxn]; int t2[maxn]; int height[maxn]; int n; int xx[maxn]; int yy[maxn]; int tree[maxn<<2]; int dd; int ans; void pushdown(int o) { if(tree[o]!=-1) { tree[o<<1]=tree[o<<1|1]=tree[o]; tree[o]=-1; } } void pushup(int o) { if(tree[o<<1]==1&&tree[o<<1|1]==1)tree[o]=1; else if(tree[o<<1]==0&&tree[o<<1|1]==0)tree[o]=0; } void build() { tree[1]=0; } void update(int l,int r,int o,int L,int R) { if(L<=l&&r<=R) { tree[o]=1; return; } pushdown(o); int m=l+r>>1; if(L<=m)update(lson,L,R); if(m 
         
           >1; query(lson); query(rson); pushup(o); } void Swap(int *&x,int *&y) { int *t=x; x=y; y=t; } void build_sa(int m) { int *x=ra,*y=t2,k,i; for(i=0;i 
          
            =0;i--)sa[--c[x[i]]]=i; for(k=1;k<=n;k<<=1) { int p=0; for(i=n-k;i 
           
             =k)y[p++]=sa[i]-k; for(i=0;i 
            
              =0;i--)sa[--c[x[y[i]]]]=y[i]; int *tt=x; x=y; y=tt; p=1;x[sa[0]]=0; for(i=1;i 
             
               =n)break; m=p; } } void getheight() { int i,k=0; for(i=0;i 
              
                r){ int temp=l; l=r; r=temp; } l++; int lo=r-l+1; int k=mm[lo]; return dp[l][k] 
               
                 < 
                
                  < 
                 
                   q[maxn]; int L,M; int head[maxn]; int next[maxn]; int edge[maxn]; int ccn[maxn]; int tem[maxn]; int solve() { int i; int d=0; dd=0; int cnt=0,l,j; for(i=0;i 
                  
                    =M){ cnt++; q[d].push_back(sa[i-1]); } else if(cnt>0){ q[d++].push_back(sa[i-1]); cnt=0; } if(cnt>0)q[d++].push_back(sa[i-1]); int l1,r1; int k; int ddd=0; for(i=0;i 
                   
                     (L-1)*M)continue; l1=v-(L-1)*M; if(l1<0)l1=0; r1=u; // printf("%d %d\n",l1,r1); if(l1>(n-(L*M)-1))continue; else if(r1>(n-(L*M)-ddxx-1))r1=n-(L*M)-ddxx-1; xx[dd]=l1; yy[dd++]=r1; // printf("%d %d %d\n",n,l1,r1); } head[ddxx]=-1; } // printf("\n"); } ddd=0; for(i=0;i 
                     
                    
                   
                  
                 
                
               
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值