Cod sursa(job #3236723)

Utilizator Sasha_12454Eric Paturan Sasha_12454 Data 30 iunie 2024 17:21:02
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <bits/stdc++.h>

std :: ifstream in ("curcubeu.in");

std :: ofstream out ("curcubeu.out");

const int NMAX = 1e6 + 5;

int n;

long long a;

long long b;

long long c;

int v[NMAX];

int jump[NMAX];

std :: stack <std :: pair<std :: pair<int, int>, int>> s;

int main()
{
    in >> n >> a >> b >> c;

    s.push(std :: make_pair(std :: make_pair(a, b), c));

    for(int i = 2; i < n; i ++)
    {
        a *= 1ll * i;

        b *= 1ll * i;

        c *= 1ll * i;

        a %= n;

        b %= n;

        c %= n;

        s.push(std :: make_pair(std :: make_pair(a, b), c));
    }

    for(int i = 1; i < n; i ++)
    {
        jump[i] = i + 1;
    }

    while(!s.empty())
    {
        a = s.top().first.first;

        b = s.top().first.second;

        c = s.top().second;

        s.pop();

        if(a > b)
        {
            std :: swap(a, b);
        }

        int i = a;

        while(i <= b)
        {
            if(!v[i])
            {
                v[i] = c;
            }
            i = jump[i];
        }

        jump[a] = std :: max(1ll * jump[a], b);
    }

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

    return 0;
}