Cod sursa(job #3142130)

Utilizator andreipirjol5Andrei Pirjol andreipirjol5 Data 19 iulie 2023 13:21:07
Problema Curcubeu Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>

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

const int NMAX = 1e6;
int v[NMAX + 5], a[NMAX + 5], b[NMAX + 5], c[NMAX + 5], n;
int color[NMAX + 5], nextOne[NMAX + 5];

void precalc_query()
{
    for(int i = 2; i <= n - 1; i++)
    {
        a[i] = (a[i - 1] * i) % n;
        b[i] = (b[i - 1] * i) % n;
        c[i] = (c[i - 1] * i) % n;
    }

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

int main()
{
    fin >> n >> a[1] >> b[1] >> c[1];
    precalc_query();

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

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

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

    fin.close();
    fout.close();
    return 0;
}