[cpp] #include <stdio.h> #include <cstring> const int maxn=2*100001; int c[maxn],a[maxn]; bool judge[100001]; int f[100001]; inline int lowbit(int x) { return x&(-x); } void update(int x,int p) { for(int i=x; i<maxn; i+=lowbit(i)) c[i]+=p; } int sum(int x) { int ans=0; for(int i=x; i>0; i-=lowbit(i)) ans+=c[i]; return ans; } int main() { int n; while(scanf("%d",&n)==1) { memset(c,0,sizeof(c)); memset(judge,false,sizeof(judge)); memset(f,0,sizeof(f)); for(int i=1; i<=2*n; i++) { scanf("%d",&a[i]); update(i,1); if(!judge[a[i]]) judge[a[i]]=true; else f[a[i]]=i; } int ans=0; for(int i=1;i<=2*n;i++) { ans+=sum(f[a[i]])-sum(i); update(f[a[i]],-1); } printf("%d\n",ans); } return 0; }