Cod sursa(job #2475719)

Utilizator DawlauAndrei Blahovici Dawlau Data 17 octombrie 2019 14:40:38
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
//#include "pch.h"
#include <fstream>
#include <vector>
#include <stack>

using namespace std;

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

int main() {

	int n, A1, B1, C1;
	fin >> n >> A1 >> B1 >> C1;

	vector <int> A(n), B(n), C(n), nxt(n), ans(n);
	A[1] = A1;
	B[1] = B1;
	C[1] = C1;

	for (int idx = 2; idx < n; ++idx) {

		A[idx] = (1LL * A[idx - 1] * idx) % n;
		B[idx] = (1LL * B[idx - 1] * idx) % n;
		C[idx] = (1LL * C[idx - 1] * idx) % n;
	}

	for (int idx = n - 1; idx >= 1; --idx) {

		int st, dr;

		if (A[idx] < B[idx])
			st = A[idx], dr = B[idx];
		else st = B[idx], dr = A[idx];

		int color = C[idx];

		nxt[idx] = dr;

		for(int id = st; id <= dr; ++id)
			if (ans[id] == 0)
				ans[id] = idx;
			else id = nxt[ans[id]];
	}

	for (int idx = 1; idx < n; ++idx)
		fout << C[ans[idx]] << '\n';
}