const int MAXN = 1e6 + 42 ;
map< char , int > to[ MAXN] ;
int link[ MAXN] , que[ MAXN] , sz = 1 ;
void add_str( string s, int k)
{
int v = 0 ;
for ( auto c: s)
{
if ( ! to[ v] [ c] ) to[ v] [ c] = sz++ ;
v = to[ v] [ c] ;
}
}
void push_links( )
{
link[ 0 ] = - 1 ;
int st = 0 , fi = 1 ;
que[ 0 ] = 0 ;
while ( st < fi)
{
int v = que[ st++ ] ;
for ( auto it: to[ v] )
{
int u = it.second ;
int c = it.first ;
int j = link[ v] ;
while ( j ! = - 1 && ! to[ j] [ c] ) j = link[ j] ;
if ( j ! = - 1 ) link[ u] = to[ j] [ c] ;
que[ fi++ ] = u;
}
}
}
Y29uc3QgaW50IE1BWE4gPSAxZTYgKyA0MjsKCm1hcDxjaGFyLCBpbnQ+IHRvW01BWE5dOwppbnQgbGlua1tNQVhOXSwgcXVlW01BWE5dLCBzeiA9IDE7Cgp2b2lkIGFkZF9zdHIoc3RyaW5nIHMsIGludCBrKQp7CiAgICBpbnQgdiA9IDA7CiAgICBmb3IoYXV0byBjOiBzKQogICAgewogICAgICAgIGlmKCF0b1t2XVtjXSkgdG9bdl1bY10gPSBzeisrOwogICAgICAgIHYgPSB0b1t2XVtjXTsKICAgIH0KfQoKdm9pZCBwdXNoX2xpbmtzKCkKewogICAgbGlua1swXSA9IC0xOwogICAgaW50IHN0ID0gMCwgZmkgPSAxOwogICAgcXVlWzBdID0gMDsKICAgIHdoaWxlKHN0IDwgZmkpCiAgICB7CiAgICAgICAgaW50IHYgPSBxdWVbc3QrK107CiAgICAgICAgZm9yKGF1dG8gaXQ6IHRvW3ZdKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHUgPSBpdC5zZWNvbmQ7CiAgICAgICAgICAgIGludCBjID0gaXQuZmlyc3Q7CiAgICAgICAgICAgIGludCBqID0gbGlua1t2XTsKICAgICAgICAgICAgd2hpbGUoaiAhPSAtMSAmJiAhdG9bal1bY10pIGogPSBsaW5rW2pdOwogICAgICAgICAgICBpZihqICE9IC0xKSBsaW5rW3VdID0gdG9bal1bY107CiAgICAgICAgICAgIHF1ZVtmaSsrXSA9IHU7CiAgICAgICAgfQogICAgfQp9
compilation info
prog.cpp:3:1: error: ‘map’ does not name a type
map<char, int> to[MAXN];
^
prog.cpp:6:14: error: variable or field ‘add_str’ declared void
void add_str(string s, int k)
^
prog.cpp:6:14: error: ‘string’ was not declared in this scope
prog.cpp:6:24: error: expected primary-expression before ‘int’
void add_str(string s, int k)
^
stdout