线段树存储每一个名字,然后连维护都不需要,直接实现查找在某某区间范围内最靠左的某个指定字母的位置,然后有了这个,就可以直接用后面的子串对前面的名字进行匹配即可,复杂度O(NMLlogM)(居然还是2988 ms水过去了,好开心)
1 /**************************************************************
2 Problem: 1622
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:2988 ms
7 Memory:2448 kb
8 ****************************************************************/
9
10 var
11 i,j,k,l,m,n,ans:longint;
12 ss:ansistring;
13 b,c:array[0..10000] of ansistring;
14 a:array[0..10000,0..26] of longint;
15 function min(x,y:longint):longint;inline;
16 begin
17 if x<y then min:=x else min:=y;
18 end;
19 function max(x,y:longint):longint;inline;
20 begin
21 if x>y then max:=x else max:=y;
22 end;
23 procedure built(z,x,y:longint);
24 var i:longint;
25 begin
26 if (x=y) then
27 a[z,ord(ss[x])-64]:=1
28 else
29 begin
30 built(z*2,x,(x+y) div 2);
31 built(z*2+1,(x+y) div 2+1,y);
32 for i:=1 to 26 do a[z,i]:=a[z*2,i]+a[z*2+1,i]
33 end;
34 end;
35 function approach(z,x,y,l,r,t:longint):longint;
36 var a1:longint;
37 begin
38 if l>r then exit(0);
39 if a[z,t]=0 then exit(0);
40 if x=y then exit(x);
41 a1:=approach(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2),t);
42 if a1<>0 then exit(a1);
43 exit(approach(z*2+1,(x+y) div 2+1,y,max(l,(x+y) div 2+1),r,t));
44 end;
45
46
47 begin
48 readln(n,m);
49 for i:=1 to n do
50 begin
51 readln(b[i]);
52 b[i]:=upcase(b[i]);
53 end;
54 for i:=1 to m do
55 begin
56 readln(c[I]);
57 c[i]:=upcase(c[i]);
58 end;
59 for i:=1 to n do
60 begin
61 ss:=b[i];
62 fillchar(a,sizeof(a),0);
63 built(1,1,length(ss));
64 ans:=0;
65 for j:=1 to m do
66 begin
67 l:=0;
68 for k:=1 to length(c[j]) do
69 begin
70 l:=approach(1,1,length(ss),l+1,length(ss),ord(c[j][k])-64);
71 if l=0 then break;
72 end;
73 if l<>0 then inc(ans);
74 end;
75 writeln(ans);
76 end;
77 end.