Cod sursa(job #3296715)

Utilizator XxThornadoxXStoica Teodora XxThornadoxX Data 15 mai 2025 19:43:14
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 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] == i)
        return i;
    return t[i] = findd(t[i]);
}

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

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

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

    if(a[1] > b[1])
        swap(a[1], b[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;

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

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

        while(x <= b[i])
        {
            rez[x] = c[i];
            if(x != y)
                t[x] = y;
            x = findd(x+1);
        }
    }

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


    fin.close();
    fout.close();

    return 0;
}