POJ 2774 suffix array: Find the longest common substring

Source: Internet
Author: User
Tags bitset

POJ 2774 suffix array: Find the longest common substring

Idea: in fact, it is very simple, that is, two strings are connected, separated by a special character in the middle, and then the longest public prefix is obtained using the suffix array, and then different in the two strings, and the longest is the longest public substring.

Note: The first string is used to determine whether it is in the same character. At first, the length of the second character is used to determine whether it is found after WA 2 is sent.

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    # Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Define mem (a, B) memset (a, B, sizeof (a) # define lson I <1, l, mid # define rson I <1 | 1, mid + 1, r # define llson j <1, l, mid # define rrson j <1 | 1, mid + 1, r # define INF 0x7fffffff # define maxn 200010 using namespace std; typedef long ll; typedef unsigned long ull; void radix (int * str, int * a, int * B, int n, int m) {static int count [maxn]; mem (count, 0); for (int I = 0; I
         
           = 0; I --) B [-- count [str [a [I] = a [I];} void suffix (int * str, int * sa, int n, int m) // calculate the suffix array sa {static int rank [maxn], a [maxn], B [maxn]; for (int I = 0; I
          
            = N? 0: rank [j + (1 <
           
             > S> ss) {ss = s + "#" + ss; copy (ss. begin (), ss. end (), a); int n = ss. size (), len = 0; suffix (a, sa, n, 256); calcHeight (a, sa, height, rank, n); for (int I = 1; I
            
              Len & (sa [I]
             
              

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.