Cod sursa(job #430169)

Utilizator doru.nituNitu Doru Constantin doru.nitu Data 30 martie 2010 20:02:18
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.53 kb
#include<cstdio>
#define dim 8192
#include<vector>
#define mod 666013

using namespace std;

unsigned int a,n,l,u;
int i,j,nr,pz;
int v[1<<20+1],b[1<<20+1];
char c[dim+1];

struct nod
{
	vector<unsigned int> x;
	vector<unsigned int> poz;
}h[mod+1];

void cit(unsigned int &x)
{
	x=0;
	while(c[pz]<'0'||c[pz]>'9')
		if(++pz==dim) fread(c,1,dim,stdin),pz=0;
	
	while(c[pz]>='0'&&c[pz]<='9')
	{
		x=x*10+c[pz]-'0';
		if(++pz==dim) fread(c,1,dim,stdin),pz=0;
	}
}

int main()
{
	freopen("secv5.in","r",stdin);
	freopen("secv5.out","w",stdout);
	
	cit(n);
	cit(l);
	cit(u);
	
	for(i=1;i<=n;++i)
	{
		cit(a);
		unsigned int ind=a%mod;
		int ok=0;
		int l=h[ind].x.size();
		for(j=0;j<l;++j)
			if(h[ind].x[j]==a)
			{
				ok=1;
				break;
			}
		if(ok) 	
			b[i]=h[ind].poz[j];
		else
		{
			b[i]=(++nr);
			h[ind].x.push_back(a);
			h[ind].poz.push_back(nr);
		}
	}
	
	j=1;
	nr=0;
	long long rezl=0,rezu=0;
	
	for(i=1;i<=n;++i)
	{
		v[b[i]]++;
		if(v[b[i]]==1) nr++;
		if(nr<l) rezl+=(long long)(i-j+1);
		else
		{
			while(nr>=l)
			{
				v[b[j]]--;
				if(!v[b[j]]) nr--;
				++j;
			}
			rezl+=(long long)(i-j+1);
		}
	}
	memset(v,0,sizeof(v));
	nr=0;
	j=1;
	
	for(i=1;i<=n;++i)
	{
		v[b[i]]++;
		if(v[b[i]]==1) nr++;
		if(nr<=u) rezu+=(long long)(i-j+1);
		else
		{
			while(nr>u)
			{
				v[b[j]]--;
				if(!v[b[j]]) nr--;
				++j;
			}
			rezu+=(long long)(i-j+1);
		}
	}
	printf("%lld\n",rezu-rezl);
	
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}