Cod sursa(job #1689660)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 14 aprilie 2016 14:23:28
Problema Curcubeu Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

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

const int dim = 1000005;

int n, a[dim], b[dim], c[dim], nxt[dim], color[dim];

int main() {

	fin >> n >> a[1] >> b[1] >> c[1];

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

		a[i] = (1LL * a[i - 1] * i) % n;
		b[i] = (1LL * b[i - 1] * i) % n;
		c[i] = (1LL * c[i - 1] * i) % n;

	}

	for (int i = 1; i < n; ++i)
		nxt[i] = i + 1;

	for (int i = n - 1; i; --i) {

		if (a[i] > b[i])
			swap(a[i], b[i]);

		for (int j = a[i]; j <= b[i]; ++j) {

			if (color[j] != 0) {
				j = nxt[j];
				--j;
				continue;
			}

			color[j] = c[i];
			nxt[j] = b[i] + 1;

		}

	}

	for (int i = 1; i < n; ++i)
		fout << color[i] << '\n';

	return 0;

}

//Trust me, I'm the Doctor!