Cod sursa(job #3191137)

Utilizator dragoncrackCandidatu Mario Luca dragoncrack Data 8 ianuarie 2024 21:06:15
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <set>
#define DIM 1000005

using namespace std;

ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");

struct op {
    int a;
    int b;
    int c;
};

int color[DIM];
op operatii[DIM];
int Next[DIM];
int n, a, b, c;

int find_next(int pos) {
    int aux = pos;
    while (Next[pos] != pos)
        pos = Next[pos];
    int res = pos;
    pos = aux;
    while (Next[pos] != res) {
        aux = Next[pos];
        Next[pos] = res;
        pos = aux;
    }
    return res;
}

int main()
{
    fin >> n;
    fin >> a >> b >> c;
    for (int i = 1; i < n; i++) {
        Next[i] = i;
        operatii[i].a = min(a, b);
        operatii[i].b = min(a, b);
        operatii[i].c = c;
        a = (1ll * a * (i + 1)) % n;
        b = (1ll * b * (i + 1)) % n;
        c = (1ll * c * (i + 1)) % n;
    }
    Next[n] = n;
    for (int j = n - 1; j > 0; j--) {
        a = operatii[j].a;
        b = operatii[j].b;
        c = operatii[j].c;
        for (int i = find_next(a); i <= b; i = Next[i]) {
            color[i] = c;
            Next[i] = find_next(i + 1);
        }
    }
    for (int i = 1; i < n; i++) {
        fout << color[i] << "\n";
    }
}