Member Avatar

#include<iostream> #include<algorithm> using namespace std; #define MAX 10000000 #include<stdlib.h> #include<string.h> char s[MAX]; int p[MAX]; int bucket[MAX],nbucket[MAX]; struct suffix { int idx; }pos[MAX]; int H=0; bool cmp(struct suffix i,struct suffix j) { if(H==0) { return s[i.idx]<s[j.idx]; } else { if(bucket[i.idx]==bucket[j.idx]) { return bucket[i.idx+H]<bucket[j.idx+H]; } else { return bucket[i.idx]<bucket[j.idx]; } } } bool cmp1(struct suffix *i,struct suffix *j) { if(H==0) { if(s[i->idx]==s[j->idx]) return true; else return false; }else{ if(bucket[i->idx]==bucket[j->idx] && bucket[i->idx+H]==bucket[j->idx+H]) return true; else return false; } } int update(int l) { int id=0,start=0,c=0; for(int i=0;i<l;i++) { if(i>0 && !cmp1(&pos[i],&pos[i-1])) { id++; start=i; } if(i!=start) c=1; nbucket[pos[i].idx]=id; } memcpy(bucket,nbucket,4*l); return c; } …

Member Avatar
0
30

The End.