Cod sursa(job #2261278)

Utilizator MiriEBlatTraditionalDmoinrciuca MiriEBlatTraditional Data 16 octombrie 2018 10:16:23
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda nu_poate_veni_deci_nu_e_shimulare Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("curcubeu.in");
ofstream fout ("curcubeu.out");
const int N = 1000003;
int n, nex[N], a[N], b[N], c[N], lol[N], viz[N];

int main()
{
    fin >> n >>  a[1] >> b[1] >> c[1];
    nex[1] =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;
        nex[i] = i;
    }
    for (int i = n - 1; i > 0; i--) {
        int x = min(a[i], b[i]), y =  max(a[i], b[i]);
        while (x <= y) {
            if (viz[x])
                x = nex[x];
            else {
                lol[x] = c[i];
                nex[x] = y + 1;
                viz[x] = 1;
                x++;
            }
        }
    }
    for (int i = 1; i < n; i++)
        fout << lol[i] <<"\n";
    return 0;
}