Cod sursa(job #798118)

Utilizator vendettaSalajan Razvan vendetta Data 15 octombrie 2012 19:30:58
Problema Curcubeu Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <fstream>

using namespace std;

#define nmax 1000005
#define ll long long

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


ll n;
ll next[nmax], rez[nmax];
ll a[nmax], b[nmax], c[nmax];
void citeste(){

    f >> n >> a[1] >> b[1] >> c[1];

    for(int i=2; i<n; i++){
        a[i] = (a[i-1]*1LL*i)%n;
        b[i] = (b[i-1]*1LL*i)%n;
        c[i] = (c[i-1]*1LL*i)%n;
    }

}

void rezolva(){

    for(int i=1; i<=n; i++) next[i]=1LL*i;

    for(int i=n-1; i>=1; i--){
        int st = min(a[i], b[i]);
        int dr = max(a[i], b[i]);
        for(int j=st; j<=dr; ){
            if (rez[j]==0){
                next[j] = 1LL*dr+1LL;
                rez[j] = c[i];
                j++;
            }else j=next[j];
        }
    }

    for(int i=1; i<n; i++) g<<rez[i] << "\n";

}

int main(){

    citeste();
    rezolva();


}