Cod sursa(job #86765)

Utilizator gigi_becaliGigi Becali gigi_becali Data 25 septembrie 2007 15:15:42
Problema Curcubeu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <cstdio>
#define maxn 1000001

struct nod { int a, b,c;};
struct sol { int next, color;};

nod A[maxn];
sol sol[maxn];

//int a[maxn], b[maxn],next[maxn], color[maxn];

int main()
{
  
  int n, a, b,c;

  freopen("curcubeu.in","r",stdin);
  scanf("%d %d %d %d\n", &n, &a,&b, &c);

  // printf("%d %d %d %d\n",n, a, b, c);
  int i, j,t;
  int p, q;
  p=a; q=b;
   a=p<?q;
   b=p>?q;

    
  for(t=1;t<n;++t)
    {
      a=(a*t)%n;
      b=(b*t)%n;
      c=(c*t)%n;
      p=a;q=b;
      a=p<?q;
       b=p>?q;
       A[t].a=a;//p<?q;
       A[t].b=b;//p>?q;
      A[t].c=c;
      //    printf("%d %d %d\n", A[t].a, A[t].b, A[t].c);
    }

 
  int nr=0;
  for(t=n-1;t>=1 ;--t)
    {
      
      a=A[t].a;
      b=A[t].b;
      c=A[t].c;
      //  p=a;q=b; 
      //a=p<?q;
      //b=p>?q;

      
      
      for(i=a;i<=b;)
	{
	  if(!sol[i].next) sol[i].next=b+1, sol[i].color=c, ++i, ++nr;
	  else i=sol[i].next;
	} 
      if(nr>=n)break;
    }
  
 
   freopen("curcubeu.out","w",stdout);
   for(i=1;i<n;++i)printf("%d\n", sol[i].color);
 
  return 0;
}