用扩展KMP做简单省力.....
#include#include #include #include using namespace std;const int maxn=100100;char T[maxn],P[maxn];int next[maxn],ex[maxn];void pre_exkmp(char P[]){ int m=strlen(P); next[0]=m; int j=0,k=1; while(j+1 >P; pre_exkmp(P); int n=strlen(P); for(int i=0;i =0;i--) { sum[lisan[i]]=sum[lisan[i+1]]+pos[lisan[i]]; } for(int i=0;i