Cod sursa(job #24386)

Utilizator m_dersidanDersidan Mihai m_dersidan Data 2 martie 2007 10:38:03
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
# include <stdio.h>

# define  _fin  "secv5.in"
# define  _fout "secv5.out"

# define  maxn  1049000
# define  prim	104999


typedef struct nod
{
	int x, v;	// numarul / valoarea
	nod *next;
}	*pnod;

pnod hash[prim];
int  crt;

int found(int x)
{
	pnod *q;
	for (q=hash[ x%prim ]; q && q->x != x; q=q->next);
	
	return q->x==x ? q->v : 0;
}
int insert(int x)
{
	int res, cr=x%prim;
	if ( res=found(x) ) return res;	// must not insert it
	
	if ( !hash[cr] )
		hash[cr] = new nod, hash[cr]->x = x, hash[cr]->v = ++crt;
	else
	{
		pnod l, r;
		for (l=hash[cr]; l->next; l=l->next);
		r = new nod, r->x=x, r->v=++crt;
	}
}

int n, l, u, viz[maxn], a[maxn];

void readf()
{
	freopen(_fin, "r", stdin);
	int i, x;
	
	for (scanf("%d%d%d", &n, &l, &u), i=1; i<=n; i++)
		 scanf("%d", &x), a[maxn]=insert(x);
}

void solve()
{
	
}