Cod sursa(job #496121)

Utilizator ZethpixZethpix Zethpix Data 27 octombrie 2010 20:26:53
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <stdio.h>

struct hash
{
	int nod;
	hash *link;
}*H[1000000];

long n,a,b,m,i,x,sol,d[1100000],j;

void add(long x)
{
	hash *p;
	p=new hash;
	p->nod=x;
	p->link=H[x%m];
	H[x%m]=p;
}

int src(long x)
{
	hash *p;
	p=H[x%m];
	int ok=0;
	while(p!=NULL)
	{
		if(p->nod==x)
		{
			ok=1;
			break;
		}
		p=p->link;
	}
	return ok;
}

int main()
{
	freopen("secv5.in","r",stdin);
	freopen("secv5.out","w",stdout);

	scanf("%ld%ld%ld",&n,&a,&b);
	m=999983;
	for(i=1;i<=m;i++) H[i]=NULL;
	d[0]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%ld",&x);
		if(src(x)==0)
		{
			d[i]=d[i-1]+1;
			add(x);
		}
		else d[i]=d[i-1];
	}

	sol=0;
	for(i=1;i<=n;i++)
	{
		x=d[n]-d[i-1];
		if(d[i]==d[i-1]) x++;
		if(x<a) break;
		else
		if(a<=x&&x<=b)
		{	j=i;
			while(j<=n)
			{
				if(d[i]!=d[j]) break;
				j++;
			}
			sol+=n-j+1;
		}
	}

	printf("%ld\n",sol);
	return 0;
}