Cod sursa(job #1612966)

Utilizator BrandonChris Luntraru Brandon Data 25 februarie 2016 09:48:23
Problema Curcubeu Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>

#define MAXSIZE 1000005

using namespace std;

ifstream cin("curcubeu.in");
ofstream cout("curcubeu.out");

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

void read() {
    cin >> 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';
    }
}

int main() {
    read();
    solve();
    print();
    return 0;
}