Cod sursa(job #1452526)

Utilizator atatomirTatomir Alex atatomir Data 21 iunie 2015 11:49:58
Problema Curcubeu Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <cstdio>

using namespace std;

#define maxN (1<<20)

long n,i,_n;
pair< long , pair<long,long> > Q[maxN];
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] = (1LL*qA[i-1]*i)%n;
        qB[i] = (1LL*qB[i-1]*i)%n;
        qC[i] = (1LL*qC[i-1]*i)%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) swap(a,b);

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

        while(s<=d){
            if(col[s]) s = wh[s];
            else{
                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;
}