Cod sursa(job #1795731)

Utilizator stefan_creastaStefan Creasta stefan_creasta Data 2 noiembrie 2016 20:15:33
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1000005;
int a[N], b[N], c[N];
int colour[N] , nextt[N];
void colorful(int i)
{
    if(a[i] > b[i])
    {
        swap(a[i] , b[i]);
    }
}

int main()
{
    int n, i, j;
    freopen("curcubeu.in","r",stdin);
    freopen("curcubeu.out","w",stdout);
    scanf("%d%d%d%d", &n, &a[1], &b[1], &c[1]);
    colorful(1);
    for(i = 2;i < n; ++i)
    {
        a[i] = (1LL * a[i - 1] * i) % n;
        b[i] = (1LL * b[i - 1] * i) % n;
        c[i] = (1LL * c[i - 1] * i) % n;
        colorful(i);
    }
    for(i = n - 1;i > 0; --i)
    {
        for(j = a[i];j <= b[i]; )
        {
            if(colour[j] == 0)
            {
                colour[j] = c[i];
                nextt[j] = b[i] + 1;
                ++j;
            }
            else
            {
                j = nextt[j];
            }
        }
    }
    for(i = 1;i < n; ++i)
    {
        printf("%d\n",colour[i]);
    }
    return 0;
}