Cod sursa(job #2293556)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 1 decembrie 2018 09:54:26
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("curcubeu.in");
ofstream out("curcubeu.out");
const int nmax = 1000005;
int a[nmax];
int b[nmax];
int c[nmax];
int v[nmax];
int next[nmax];
int n;

void citire()
{
    in >> n >> a[1] >> b[1] >> c[1];
}

void precalc()
{
    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]);
    }
}

void cerinta()
{
    int st, dr;
    for(int q = n - 1; q >= 1; q --)
    {
        st = a[q];
        dr = b[q];
        while(st <= dr)
        {
            if(v[st] == 0)
            {
                v[st] = c[q];
                next[st] = b[q] + 1;
                st ++;
            }
            else
                st = next[st];
        }
    }
}

void afisare()
{
    for(int i = 1; i < n; i ++)
        out << v[i] << '\n';
}

int main()
{
    citire();
    precalc();
    cerinta();
    afisare();
    return 0;
}