Cod sursa(job #3193014)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 13 ianuarie 2024 19:25:04
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>

using namespace std;

ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");

const int DIM = 1000010;

int n;
int a[DIM], b[DIM], c[DIM];
int nextPos[DIM], color[DIM];

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

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

    for (int i = n - 1; i >= 1; i--) {
        if (a[i] > b[i])
            swap(a[i], b[i]);

        for (int j = a[i]; j <= b[i]; j++) {
            if (color[j] != 0) {
                j = nextPos[j] - 1;
            } else {
                color[j] = c[i];
                nextPos[j] = b[i] + 1;
            }
        }
    }

    for (int i = 1; i < n; i++)
        fout << color[i] << '\n';

    return 0;
}