Cod sursa(job #1772525)

Utilizator CrystyAngelDinu Cristian CrystyAngel Data 6 octombrie 2016 20:18:37
Problema Curcubeu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("curcubeu.in");
ofstream g("curcubeu.out");

#define nmax 1101000

int a[nmax];
int b[nmax];
int c[nmax];
int ans[nmax];
int ne[nmax];
int i,s,d,col,n,j;

int main()
{
    f>>n>>a[1]>>b[1]>>c[1];
    for(i=2; i<n; ++i)
    {
        a[i]=(a[i-1]*i)%n;
        b[i]=(b[i-1]*i)%n;
        c[i]=(c[i-1]*i)%n;
    }
    for(i=1; i<n; ++i)
        ne[i]=i;
    for(i=n-1; i>0; --i)
    {
        s=a[i];
        d=b[i];
        col=c[i];
        if(s>d)
            swap(s,d);
        for(j=s; j<=d; ++j)
        if(!ans[j])
        {
            ans[j]=col;
            ne[j]=d;
        }
        else
        j=ne[j];
    }
    for(i=1; i<n; ++i)
       g<<ans[i]<<'\n';
}