1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 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 100000717 #define mod 100000000718 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< <
dp[i]=dp[i-1]-A+B