G.Colorful String(The Preliminary Contest for ICPC Asia Xuzhou 2019)

https://nanti.jisuanke.com/t/4

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=6e5+10,base =131;
 4 typedef unsigned long long ull;
 5 char str[N];
 6 ull hl[N],hr[N],p[N];
 7 
 8 int mark[N][30];
 9 
10 
11 ull get(ull h[],int l,int r)
12 {
13     return h[r]-h[l-1]*p[r-l+1];
14 }
15 
16 int k=0;
17 long long getval(int l,int r)
18 {
19     if(l==r&&str[r]=='z'+1)
20         return 0;
21     long long sum=0;
22     if(str[l]=='z'+1)
23         l++;
24     for(int i=1;i<=26;++i)
25     {
26         int temp=(mark[r][i]-l+2)/2;
27         if(temp<0)
28             continue;
29         sum+=temp;
30     }
31     return sum;
32 }
33 int main()
34 {
35 
36 
37     cin>>(str+1);
38     int n=strlen(str+1);
 39  
40      for ( int I = * n- 2 ; I> 0 ; = I- 2 ) // Key i- = 2 analog kmp add a character 
41 is      {
 42 is          STR [I] STR = [I / 2 ];
 43 is          STR [I- . 1 ] = ' Z ' + . 1 ;
 44 is          // interposition of an unwanted number 
45      }
 46 is  
47      n-= 2 * n-;
 48      P [ 0 ] = . 1 ;
 49      for ( int i=1;i<=n;++i)
50     {
51         for(int j=1;j<=26;++j)
52         {
53             mark[i][j]=mark[i-1][j];
54             if(str[i]!='z'+1)
55                 mark[i][str[i]-'a'+1]=i;
56         }
57     }
58     for(int  i=1, = n-J; <= n-I; ++ I, J, )
 59      {
 60          HL [I] HL = [I- . 1 ] * Base + STR [I] - ' A ' + . 1 ; // positive sequence Ha value Xi -> 
61 is          HR [I] = HR [I- . 1 ] * Base + STR [J] - ' a ' + . 1 ; // hash value of the reverse -> this is necessary 
62 is          P [I] = P [I- . 1 ] * Base ;
 63 is      }
 64  
65  
66      Long  Long ANS = 0 ;
 67      for( Int I = . 1 ; I <= n-; I ++) // Enumeration each character as a midpoint 
68      {
 69          int L = 0 , R & lt = min (I- . 1 , N- I);
 70          the while (L < R & lt )
 71 is          {
 72              int MID = L + R & lt + . 1 >> . 1 ; // length of the radius
 73 is  
74  
75              // ! IF (GET (HL, MID-I, I-. 1) = GET (HL,. 1 + I, + I MID))
 76              // interpretation interval judgment about indeed but the values are -> direction
 77              // reason is that it must be the reverse order of 
78  
79              IF ( GET(HL, MID-I, I- . 1 )! = GET (HR, N- (MID + I) + . 1 , N- (I + . 1 ) + . 1 ))
 80              {
 81                  // If not certainly decrease the radius 
82                  mid- = R & lt . 1 ;
 83              }
 84              the else L = MID;
 85          }
 86          ANS + = GetVal (I- L, I);
 87      }
 88      the printf ( " % LLD \ n- " , ANS);
 89      return  0 ;
 90 }

 

 

1389

solution:

Hash binary string back to the text string.

 

Guess you like

Origin www.cnblogs.com/--HPY-7m/p/11482418.html