Cod sursa(job #2648499)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 11 septembrie 2020 11:28:58
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    freopen ("curcubeu.in", "r", stdin);
    freopen ("curcubeu.out", "w", stdout);
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    n--;
    vector<int> col(n, 0), a(n), b(n), c(n);
    set<int> s;
    a[0] = min(x, y);
    b[0] = max(x, y);
    c[0] = z;
    s.insert(0);
    for (int i = 1; i < n; i++)
    {
        s.insert(i);
        x = (ll) x * (i + 1) % (n + 1);
        y = (ll) y * (i + 1) % (n + 1);
        z = (ll) z * (i + 1) % (n + 1);
        a[i] = min(x, y);
        b[i] = max(x, y);
        c[i] = z;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        int l = a[i] - 1, r = b[i] - 1, x = c[i];
        while (1)
        {
            auto it = s.lower_bound(l);
            if (it == s.end() || *it > r)
            {
                break;
            }
            col[*it] = x;
            s.erase(it);
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d\n", col[i]);
    }
}