Cod sursa(job #3296710)

Utilizator XxThornadoxXStoica Teodora XxThornadoxX Data 15 mai 2025 19:32:19
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <vector>

using namespace std;

vector<int> a, b, c, t, rez;
int n;

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

int findd(int i)
{
    if(t[i] == 0)
        return i;
    return t[i] = findd(t[i]);
}

int unionn(int x, int y)
{
    if(x != y)
        t[x] = y;
}

int main()
{
    fin >> n;
    a.resize(n+1), b.resize(n+1), c.resize(n+1), t.resize(n+1), rez.resize(n+1);

    fin >> a[0] >> b[0] >> c[0];

    if(a[0] > b[0])
        swap(a[0], b[0]);

    for(int i = 1; i < n-1; 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;

        if(a[i] > b[i])
            swap(a[i], b[i]);
    }

    for(int i = n-2; i >= 0; i--)
    {
        int x = findd(a[i]), y = findd(b[i]+1);

        while(x <= b[i])
        {
            rez[x] = c[i];
            unionn(x, b[i]+1);
            x = findd(x+1);
        }
    }

    for(int i = 0; i <= n-2; i++)
        fout << rez[i] << "\n";


    return 0;
}