Cod sursa(job #1465457)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 27 iulie 2015 13:58:52
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#include <algorithm>

using namespace std;

int a[1000010], b[1000010], c[1000010], v[1000010], nn[1000010];

inline int nxt (int x)
{
    if (!nn[x]) return x;
    nn[x] = nxt (nn[x]);
    return nn[x];
}

int main ()
{
    freopen ("curcubeu.in", "r", stdin);
    freopen ("curcubeu.out", "w", stdout);

    int n;
    scanf ("%d %d %d %d", &n, &a[1], &b[1], &c[1]);

    for (int i = 2; i <= n; ++i)
    {
        long long aa = 1LL * (1LL * a[i - 1] * i) % n;
        long long bb = 1LL * (1LL * b[i - 1] * i) % n;
        long long cc = 1LL * (1LL * c[i - 1] * i) % n;

        a[i] = (int)aa;
        b[i] = (int)bb;
        c[i] = (int)cc;
    }

    for (int i = n; i; --i)
    {
        int x = min (a[i], b[i]);
        int y = max (a[i], b[i]);

        for (int j = nxt (x); j <= y; j = nxt (j + 1))
        {
            v[j] = c[i];
            nn[j] = y + 1;
        }
    }

    for (int i = 1; i < n; ++i)
        printf ("%d\n", v[i]);

    return 0;
}