Cod sursa(job #11648)

Utilizator DITzoneCAdrian Diaconu DITzoneC Data 1 februarie 2007 01:20:30
Problema Secventa 5 Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <stdio.h>

#define FOR(i,s,d) for(i=(s);i<(d);++i)
#define RS 65535
#define SL 16

typedef unsigned int uint;
typedef long long lint;

uint n,A[1<<20],u,l;
int H[RS+1][SL];
//set <uint> S[RS+1];
uint B[1<<20];

lint doit(uint l)
{	
	if(!l)
		return 0;
	uint i,j=0,nr=0;
	lint sol=0;
	FOR(i,0,n)
	{
		for(;nr<=l&&j<n;j++)
		{
			if(!B[A[j]])
				nr++;
			B[A[j]]++;
		}
		sol+=j-i-(nr<=l?0:1);
		B[A[i]]--;
		if(!B[A[i]])
			nr--;
	}
	return sol;
}

char s[64];

uint cit()
{
	uint i,j=0;
	fgets(s,64,stdin);
	for(i=0;s[i]>='0'&&s[i]<='9';i++)
		j=j*((uint)10)+((uint)(s[i]-'0'));
	return j;
}

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

	int i,j=0,jj;
	uint x,y;
	uint xx;
	fgets(s,64,stdin);
	sscanf(s,"%u %u %u",&n,&u,&l);

	FOR(i,0,n)
	{
		xx=cit();
		x=xx>>SL,y=(xx&RS)^x;
		x++;
		FOR(jj,0,SL)
			if(H[y][jj]==x||!H[y][jj])
				break;		
		if(!H[y][jj])
			H[y][jj]=x;
		A[i]=(y<<4)|jj;
/*
		if(C[x]&&C[y]&&H[y][x])
			A[i]=H[y][x]-1;
		else
			C[x]=C[y]=1,++j,H[y][x]=j,A[i]=j-1;
			*/
	}

	printf("%lld\n",doit(l)-doit(u-1));
	return 0;
}