Cod sursa(job #764285)

Utilizator vendettaSalajan Razvan vendetta Data 4 iulie 2012 17:49:27
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>

using namespace std;

#define nmax 1000005

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

struct{int a,b,c;}a[nmax];
int n, next[nmax], rez[nmax];

void citeste(){

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

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

}

void rezolva(){

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

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

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

}

int main(){

    citeste();
    rezolva();


}