Cod sursa(job #460059)

Utilizator crawlerPuni Andrei Paul crawler Data 1 iunie 2010 02:51:21
Problema Curcubeu Scor 80
Compilator c Status done
Runda Arhiva de probleme Marime 1 kb
#include <stdio.h>

#define Nmax 1000100

int a[Nmax];
int b[Nmax];
int c[Nmax];
int next[Nmax];
int col[Nmax], n;

int nextX(int poz) {
  if (next[poz] == poz)
    return poz;
  return next[poz] = nextX(next[poz]);
}

int main() {
  fscanf(fopen("curcubeu.in","r"), "%d%d%d%d", &n, a+1, b+1, c+1);
  
  int i, j;
  next[1] = 1;
  for (i = 2; i <= n; ++i) {
    a[i] = (long long)((long long)i*(long long)a[i-1])%(long long)n;
    b[i] = (long long)((long long)i*(long long)b[i-1])%(long long)n;
    if (a[i] > b[i]) {
      c[i] = a[i];
      a[i] = b[i];
      b[i] = c[i];
    }
    c[i] = (long long)((long long)i*(long long)c[i-1])%(long long)n;
    next[i] = i;
  }
  next[n+1] = n + 1;
  next[n+2] = n + 2;
  next[n+3] = n + 3;

  for ( i = n-1; i > 0; --i)
  for ( j = nextX(a[i]); j <= b[i]; j = nextX(j)) {
    col[j] = c[i];
    next[j] = nextX(j+1);
  }

  freopen("curcubeu.out", "w", stdout);
  for (i = 1; i < n; ++i)
    printf("%d\n", col[i]);

  return 0;
}