Cod sursa(job #1452539)

Utilizator atatomirTatomir Alex atatomir Data 21 iunie 2015 12:10:46
Problema Curcubeu Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>

using namespace std;

#define maxN (1<<20)
#define ll long long

long n,i,_n;
long qA[maxN],qB[maxN],qC[maxN];
long a,b,c;
long col[maxN];
long wh [maxN];

int main()
{
    freopen("curcubeu.in","r",stdin);
    freopen("curcubeu.out","w",stdout);

    scanf("%ld %ld %ld %ld",&n,&qA[1],&qB[1],&qC[1]);
    _n = n;

    for(i=2;i<n;i++){
        qA[i] = ((ll)i*qA[i-1])%n;
        qB[i] = ((ll)i*qB[i-1])%n;
        qC[i] = ((ll)i*qC[i-1])%n;
    }

    for(i=1;i<n;i++) wh[i] = i+1;

    for(;--n>0;){
        a = qA[n];
        b = qB[n];
        c = qC[n];
        if(a>b) {long t=a;a=b;b=t;}

        //! solve...
        long s = a,d=b,what=c;
        long _fin=d+1,_s;

        while(s<=d){
            if(!col[s]) col[s] = what;
            _s = s;
            s = wh[s];
            wh[_s] = _fin;
        }
    }

    n = _n;
    for(i=1;i<n;i++) printf("%ld\n",col[i]);

    return 0;
}