摘要: AC自动机裸题 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxnode=10000*50+5; 6 char in[1000000+5]; 7 struct Trie 8 { 9 int ch[maxnode][26];10 int val[maxnode];11 int fail[maxnode];12 int sz;13 void initial(){sz=1;memset(ch[0],0,sizeof(ch[0]));memset(val,0,sizeo... 阅读全文
posted @ 2013-10-12 18:01 sooflow 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 模拟水题 1 #include 2 #include 3 4 const int maxn=1000000+5; 5 6 int b[maxn]; 7 int e[maxn]; 8 9 int main()10 {11 // freopen("icpc.in","r",stdin);12 // freopen("icpc.out","w",stdout);13 int B,E;14 while(scanf("%d%d",&B,&E)!=EOF)15 {16 int t=0;17 阅读全文
posted @ 2013-10-10 21:51 sooflow 阅读(364) 评论(0) 推荐(0) 编辑
摘要: kmp next数组应用。 1 #include 2 #include 3 const int maxn=1000000+5; 4 char s[maxn]; 5 int next[maxn]; 6 int snext[maxn]; 7 void get_next(char *T,int len,int *next) 8 { 9 next[0]=-1;10 for(int i=1;i=0)14 j=next[j];15 if(T[i]==T[j+1])next[i]=j+1;16 else next[i]=0;17 }1... 阅读全文
posted @ 2013-10-10 21:50 sooflow 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 二分查找 1 #include 2 #define min(a,b) (a=a[i])14 sum+=(tmp-a[i])/c[i]+1;15 }16 return sum;17 }18 int main()19 {20 while(scanf("%d",&n)!=EOF)21 {22 for(int i=0;i>1;28 if(cal(mid)&1) r=mid;29 else l=mid+1;30 }31 if(l==1LL=a[i]&&l... 阅读全文
posted @ 2013-09-30 23:55 sooflow 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 比赛的时候感觉是线段树,直接求,超时了。看了题解,才知道是有点规律的,要先固定端点,求出所有以该端点为左端点的区间,然后不断移动左端点,直到求出所有区间。用nxt[i]存储下一个出现a[i]的下标。先求出所有的mex(1,i)再删除a[1],则在区间(2,nxt[1]-1)上mex(2,i)>a[1]的值全部改为a[1],因为mex(2,i)是递增的,所以可以求出第一个大于a[1]的mex(2,i)的下标,然后进行区间更新。以此类推,从左到右删除所有元素,就可以得出答案。 1 #include 2 #include 3 #include 4 #include 5 using name.. 阅读全文
posted @ 2013-09-18 18:20 sooflow 阅读(770) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 const int maxn=100000+5; 4 int sum[maxn>1;31 if(Lm) update(L,R,inc,m+1,r,rt>1;44 if(lm) ret+=query(L,R,m+1,r,rt<<1|1);46 return ret;47 }48 int n,m;49 int main()50 {51 int t;52 scanf("%d",&t);53 while(t--)54 {55 scanf("%d%d",&n,&m);5 阅读全文
posted @ 2013-09-07 16:59 sooflow 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=100000+5; 6 int num[maxn>1;23 build(l,m,rt>1;35 if(x>1;46 if(Rm) return query(L,R,m+1,r,rt<<1|1);48 int a=query(L,R,l,m,rt<<1);49 int b=query(L,R,m+1,r,rt<<1|1);50 return min(a,b);51 }52 int main()53 阅读全文
posted @ 2013-09-07 16:56 sooflow 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 这道又是submission error ,先存下档。 1 #include 2 #include 3 const int maxnode=4000*1000+10; 4 int ch[maxnode][62]; 5 int val[62]; 6 int sz; 7 int index(char ch) 8 { 9 if(ch>='0'&&ch'A'&&ch1) ans+=val[i];49 ans+=((n-1)*n)/2;50 printf("Case %d: %d\n",kcase++,ans);5 阅读全文
posted @ 2013-08-26 20:38 sooflow 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 递推式:d[i]=sum(d[i+len[x]])这道题的数据真狗血,改了一点就过了。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxnode=4000*100+10; 6 const int mod=20071027; 7 const int maxn=300000 + 10; 8 const int maxw=4000 + 10; 9 char ss[maxn];10 char s[110];11 int d[maxn];12 int len[maxw];13 int ch[maxnode][2 阅读全文
posted @ 2013-08-26 19:51 sooflow 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 因为查询的前缀字典可能不含有,这点没考虑清楚就码了,太粗心了,因为case只有一个,很多初始化操作都不需要了。 1 #include 2 #include 3 const int maxnode=500000; 4 int ch[maxnode][26]; 5 int val[maxnode]; 6 int sz; 7 void insert(char *s) 8 { 9 int u=0,len=strlen(s);10 for(int i=0;i<len;i++)11 {12 int c=s[i]-'a';13 if(!ch[u][c]... 阅读全文
posted @ 2013-08-26 14:38 sooflow 阅读(146) 评论(0) 推荐(0) 编辑