出来冒个泡
由于数比较大 开了map计数 然后边走边删边加 勉强可过
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<queue> 7 #include<map> 8 #include<string> 9 using namespace std; 10 #define LL long long 11 #define N 200010 12 int a[N],b[N],ff[N],o[N],g,vis[N]; 13 map<int,int>f; 14 map<int,int>q; 15 map<int,int>qq; 16 int main() 17 { 18 int i,kq=0; 19 LL n,m,p; 20 cin>>n>>m>>p; 21 for(i = 1; i <= n ; i++) 22 cin>>a[i]; 23 for(i = 1; i <= m ; i++) 24 { 25 cin>>b[i]; 26 if(!q[b[i]]) kq++; 27 q[b[i]]++; 28 } 29 int k = 0; 30 for(int e = 1; e <= n ; e++) 31 { 32 if(vis[e]) continue; 33 if(e+(m-1)*p>n) break; 34 k = 0; 35 f.clear();qq.clear(); 36 while(k<m&&e+k*p<=n) 37 { 38 f[a[e+k*p]]++; 39 vis[e+k*p] = 1; 40 k++; 41 } 42 int s=0; 43 for(i = 1; i <= m ; i++) 44 { 45 if(f[b[i]]==q[b[i]]&&!qq[b[i]]) 46 { 47 s++; 48 qq[b[i]] = 1; 49 } 50 } 51 if(s==kq) 52 { 53 g++; 54 o[g] = e; 55 } 56 int j = e+p; 57 while(j+(m-1)*p<=n) 58 { 59 int k1 = f[a[j-p]],k2 = q[a[j-p]],k3 = f[a[j+(m-1)*p]],k4 = q[a[j+(m-1)*p]]; 60 f[a[j-p]]--; 61 f[a[j+(m-1)*p]]++; 62 vis[j+(m-1)*p] = 1; 63 if(a[j-p]!=a[j+(m-1)*p]) 64 { 65 if(q[a[j-p]]) 66 { 67 if(k1==k2) 68 s--; 69 else if(f[a[j-p]]==q[a[j-p]]){s++;} 70 } 71 if(q[a[j+(m-1)*p]]) 72 { 73 if(k3==k4) s--; 74 else if(f[a[j+(m-1)*p]]==q[a[j+(m-1)*p]]) s++; 75 } 76 } 77 if(s==kq) 78 { 79 g++; 80 o[g] = j; 81 } 82 j+=p; 83 } 84 } 85 sort(o+1,o+g+1); 86 cout<<g<<endl; 87 for(i = 1 ; i <= g ; i++) 88 cout<<o[i]<<" "; 89 return 0; 90 }