Cod sursa(job #1612989)

Utilizator BrandonChris Luntraru Brandon Data 25 februarie 2016 10:01:43
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <cstdio>
#include <algorithm>

#define MAXSIZE 1000005

using namespace std;

int n, nxt[MAXSIZE], clr[MAXSIZE], a[MAXSIZE], b[MAXSIZE], c[MAXSIZE];

void read() {
    //cin >> n >> a[1] >> b[1] >> c[1];
    scanf("%d%d%d%d", &n, &a[1], &b[1], &c[1]);

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

void solve() {
    for(int i = n - 1; i >= 1; --i) {
        int l = min(a[i], b[i]);
        int r = max(a[i], b[i]);

        for(int j = l; j <= r;) {
            if(clr[j]) {
                j = nxt[j];
                continue;
            }

            nxt[j] = r + 1;
            clr[j] = c[i];
            ++j;
        }
    }
}

void print() {
    for(int i = 1; i < n; ++i) {
        //cout << clr[i] << '\n';
        printf("%d\n", clr[i]);
    }
}

int main() {
    freopen("curcubeu.in", "r", stdin);
    freopen("curcubeu.out", "w", stdout);
    read();
    solve();
    print();
    return 0;
}