Cod sursa(job #2352192)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 23 februarie 2019 08:27:46
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <cstdio>

using namespace std;

const int N = (int)1e6 + 7;

int n;
int a[N];
int b[N];
int c[N];

int r[N];

int urm[N];

int main()
{
        freopen("curcubeu.in", "r", stdin);
        freopen("curcubeu.out", "w", stdout);
        scanf("%d", &n);
        scanf("%d%d%d", &a[1], &b[1], &c[1]);
        r[1] = -1;
        for(int i = 2; i < n; i++)
        {
                a[i] = a[i - 1] * (long long)i % n;
                b[i] = b[i - 1] * (long long)i % n;
                c[i] = c[i - 1] * (long long)i % n;
                r[i] = -1;
        }
        for(int i = n - 1; i >= 1; i--)
        {
                int st;
                int dr;
                if(a[i] < b[i])
                {
                        st = a[i];
                }
                else
                {
                        st = a[i];
                }
                dr = a[i] + b[i] - st;
                int kol = c[i];
                for(int j = st; j <= dr;)
                {
                        if(r[j] == -1)
                        {
                                r[j] = kol;
                                urm[j] = dr + 1;
                        }
                        else
                        {
                                j = urm[j];
                        }
                }
        }
        for(int i = 1; i < n; i++)
        {
                if(r[i] == -1)
                {
                        r[i] = 0;
                }
                printf("%d\n", r[i]);
        }
        return 0;
}