Cod sursa(job #3331332)

Utilizator boboc132Boboc Teodor boboc132 Data 26 decembrie 2025 18:22:30
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

const int MAX = 1000010; // Extra buffer
int T[MAX], sol[MAX]; // Schimbat in int pentru siguranta memoriei

int get_root(int nod) {
    int root = nod;
    while (T[root] != root) root = T[root];
    while (T[nod] != root) {
        int aux = T[nod];
        T[nod] = root;
        nod = aux;
    }
    return root;
}

int main() {
    ios_base::sync_with_stdio(0); in.tie(0);
    int n;
    long long Ar, Br, Cr;
    if (!(in >> n >> Ar >> Br >> Cr)) return 0;

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

    for (int i = 1; i < n; i++) {
        int st = (int)(min(Ar, Br) + 1);
        int dr = (int)(max(Ar, Br) + 1);

        // Bucla reparata: folosim o variabila auxiliara pentru salt
        int j = get_root(st);
        while (j <= dr) {
            sol[j] = (int)Cr;
            T[j] = get_root(j + 1); 
            j = get_root(j); // Salt direct la urmatoarea celula libera
        }

        Ar = (Ar * (i + 1)) % n;
        Br = (Br * (i + 1)) % n;
        Cr = (Cr * (i + 1)) % n;
    }

    for (int i = 1; i < n; i++) {
        out << sol[i] << "\n";
    }
    return 0;
}