#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define maxn 100005 #define maxm 2000000 int na,nb,now[maxm],prep[maxn],val[maxn]; void read(int &x){ x=0; int f=1; char ch; for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) f=-1; for (;isdigit(ch);ch=getchar()) x=x*10+ch-‘0‘; x*=f; } void Ha(int x){ int pos=val[x]%maxm+1; prep[x]=now[pos],now[pos]=x; } bool search(int x){ int pos=x%maxm+1; bool bo=0; for (int i=now[pos];i;i=prep[i]){ if (val[i]==x){ bo=1; break; } } return bo; } int main(){ memset(now,0,sizeof(now)); read(na); for (int i=1;i<=na;i++) read(val[i]),Ha(i); int ans=0; read(nb); int x; for (int i=1;i<=nb;i++){ read(x); if (!search(x)) ans++; } printf("%d\n",ans); return 0; }
8 1 2 3 4 5 6 7 8
6 2 3 4 5 6 7
原文:http://www.cnblogs.com/LHR-HY/p/6351507.html