Cod sursa(job #3358211)

Utilizator Minea_TheodorMinea Theodor Stefan Minea_Theodor Data 15 iunie 2026 11:19:28
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int n;
const int MAXIM=1e7+5;
int a[MAXIM], b[MAXIM], c[MAXIM], cul[MAXIM], parent[MAXIM];
int root(int x)
{
    while(x!=parent[x])
        x=parent[x];
    return x;
}
signed main()
{
    fin >> n >> 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]=a[i-1]*i%n;
        b[i]=b[i-1]*i%n;
        c[i]=c[i-1]*i%n;
        if(a[i]>b[i])
            swap(a[i], b[i]);
    }
    for(int i=0; i<=n; i++)
        parent[i]=i;
    for(int i=n-1; i >0; i--)
    {
        int x = root(a[i]);
        while(x<=b[i])
        {
            cul[x]=c[i];
            parent[x]=b[i]+1;
            x=-root(x+1);
        }
    }
    for(int i=0; i < n; i++)
        fout << cul[i] << '\n';
    return 0;
}