Hdu4455Substrings dp,
// Dp [I + 1] = dp [I] + dis [I]-c [I];
// Dp [I] indicates the sum of different numbers of substrings whose lengths are I.
// Dis [I] indicates that the shortest distance of all vertices prior to them is greater than or equal to the sum of I.
// C [I] indicates the sum of different numbers of the last subsequence with the length of I
# Include <iostream>
# Include <cstdio>
# Include <cstring>
Using namespace std;
Const int maxn = 1000010;
_ Int64 dp [maxn];
Int a [maxn];
Int dis [maxn];
Int last [maxn];
Int Hash [maxn];
Int main ()
{
// Freopen ("in.txt", "r", stdin );
Int N; int Q;
While (scanf ("% d", & N)
{
Memset (Hash, 0, sizeof (Hash ));
Memset (dis, 0, sizeof (dis ));
For (int I = 1; I <= N; I ++)
{
Scanf ("% d", & a [I]);
If (Hash [a [I])
Dis [I-Hash [a [I] ++;
Else
Dis [I] ++; // For a number that is not the same as before, it is assumed that the number of vertices with the same number is 0.
Hash [a [I] = I;
}
Memset (Hash, 0, sizeof (Hash ));
For (int I = N; I> 0; I --)
{
Dis [I] + = dis [I + 1];
Last [I] = last [I + 1];
If (! Hash [a [I])
Last [I] ++;
Hash [a [I] = 1;
}
Dp [1] = N;
For (int I = 2; I <= N; I ++)
Dp [I] = dp [I-1] + (_ int64) dis [I]-(_ int64) last [N-I + 2];
Scanf ("% d", & Q );
While (Q --)
{
Int query;
Scanf ("% d", & query );
Printf ("% I64d \ n", dp [query]);
}
}
Return 0;
}