1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <fstream> 5 #include <algorithm> 6 #include <stdio.h> 7 #include <vector> 8 #include <queue> 9 #include <set> 10 #include <cmath> 11 using namespace std; 12 const double eps = 1e-8; 13 const double pi=acos(-1.0); 14 const int INF=0x7fffffff; 15 unsigned long long uINF = ~0LL; 16 #define MAXN 1000007 17 #define mod 1000000007 18 typedef long long LL; 19 int a[MAXN],pos[MAXN],hash[MAXN],last[MAXN]; 20 LL dp[MAXN]; 21 int main() 22 { 23 //freopen("0.in","r",stdin); 24 //freopen("01.in","w",stdout); 25 int n,q,w,dis; 26 while(scanf("%d",&n),n!=0) 27 { 28 memset(hash,0,sizeof(hash)); 29 memset(pos,0,sizeof(pos)); 30 for(int i=1;i<=n;i++) 31 { 32 scanf("%d",&a[i]); 33 pos[i-hash[a[i]]]++; 34 hash[a[i]]=i; 35 } 36 memset(hash,0,sizeof(hash)); 37 last[0]=0; 38 for(int i=n;i>=1;i--) 39 { 40 hash[a[i]]++; 41 if(hash[a[i]]==1)last[n-i+1]=last[n-i]+1; 42 else last[n-i+1]=last[n-i]; 43 } 44 dp[1]=n; 45 int sum=n; 46 for(int i=2;i<=n;i++) 47 { 48 sum-=pos[i-1]; 49 //cout<<sum<<endl; 50 dp[i]=dp[i-1]-last[i-1]+sum; 51 } 52 53 scanf("%d",&q); 54 for(int i=0;i<q;i++) 55 { 56 scanf("%d",&w); 57 printf("%I64d ",dp[w]); 58 } 59 } 60 return 0; 61 }
dp[i]=dp[i-1]-A+B