Cod sursa(job #534950)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 16 februarie 2011 16:40:55
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<cstdio>
#define LL long long
#define NM 1000001
#define maxim(a,b) ((a>b)?a:b)
#define minim(a,b) ((a<b)?a:b)
LL a[NM],b[NM],c[NM];
int N,cul[NM],maxx,minn,gr[NM];
inline void mod(LL &x)
{
	if (x>=N)
		x%=N;
}
inline void color()
{
	int num=0;
	for (int i=N-1; i&&num<N-1; --i)
	{
		maxx=maxim(a[i],b[i]);
		minn=minim(a[i],b[i]);
		for (int j=minn; j<=maxx; )
		{
			if (cul[j]==-1)
			{
				++num;
				cul[j]=c[i];
				gr[j]=maxim(gr[maxx],gr[j]);
				++j;
				continue;
			}
			int cj =j;
			j=gr[j]-1;
			gr[j]=maxim(gr[j],gr[maxx]);
			gr[cj]=maxim(gr[cj],gr[maxx]);
			if (j==maxx)
				break;
		}
		
	}
}
inline void afis()
{
	int i;
	for (i=1; i<N; ++i)
		printf("%d\n",(cul[i]==-1)?0:cul[i]);
}
int main()
{
	freopen("curcubeu.in","r",stdin);
	freopen("curcubeu.out","w",stdout);
	scanf("%d%lld%lld%lld",&N,&a[1],&b[1],&c[1]);
	cul[1]=-1;
	gr[1]=2;
	for (int i=2; i<N; ++i)
	{
		gr[i]=i+1;
		cul[i]=-1;
		a[i]=i*a[i-1];
		b[i]=i*b[i-1];		
		c[i]=i*c[i-1];
		mod(a[i]);
		mod(b[i]);
		mod(c[i]);
	}
	gr[N]=N+1;
	color();
	afis();
	return 0;
}