zoukankan      html  css  js  c++  java
  • 【BZOJ4641】—基因改造(Kmp)

    传送门
    bzojbzoj关了,干脆别开了 ,只有darkbzojdarkbzoj

    这道题和这道有区别???

    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<20|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ob==ib)?EOF:*ib++;
    }
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define ll long long
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define cs const
    #define bg begin
    #define poly vector<int>
    #define chemx(a,b) ((a)<(b)?(a)=(b):0)
    #define chemn(a,b) ((a)>(b)?(a)=(b):0)
    cs int N=1000005;
    int fail[N],T,c,last[N];
    int a[N],b[N],v[N],n,m,ans[N],tot;
    inline bool comp(int a,int b,int l){
    	return (a==b)||(a>l&&b>l);
    }
    int main(){
    	T=read(),c=read();
    	while(T--){
    		n=read(),m=read(),tot=0;
    		for(int i=1;i<=n;i++)v[i]=read();
    		memset(last,0,sizeof(int)*(c+1));
    		for(int i=1;i<=n;i++)a[i]=i-last[v[i]],last[v[i]]=i;
    		for(int i=1;i<=m;i++)v[i]=read();
    		memset(last,0,sizeof(int)*(c+1));
    		for(int i=1;i<=m;i++)b[i]=i-last[v[i]],last[v[i]]=i;
    		for(int i=0,j=2;j<=m;j++){
    			while(i&&!comp(b[i+1],b[j],i))i=fail[i];
    			if(comp(b[i+1],b[j],i))i++;
    			fail[j]=i;
    		}
    		for(int i=0,j=1;j<=n;j++){
    			while(i&&!comp(b[i+1],a[j],i))i=fail[i];
    			if(comp(b[i+1],a[j],i))i++;
    			if(i==m)ans[++tot]=j-i+1,i=fail[i];
    		}
    		cout<<tot<<'
    ';
    		for(int i=1;i<=tot;i++)cout<<ans[i]<<" ";puts("");
    	}
    }
    
  • 相关阅读:
    漫谈五种IO模型
    jvm调优-命令大全(jps jstat jmap jhat jstack jinfo)
    Intellij IDEA 插件开发秘籍
    二进制
    java程序员必知的 8大排序
    Redis常见问题
    BitMap位图
    编程思想
    Final修饰的字段是否可以通过反射设置值
    ORACLE 11g ORA-20000: Unable to analyze TABLE "AA"."CMP3$87651", insufficient privileges or does not exist
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328475.html
Copyright © 2011-2022 走看看