Cod sursa(job #1689675)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 14 aprilie 2016 14:37:40
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

const int dim = 1000005;

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

int main() {

	freopen("curcubeu.in", "r", stdin);
	freopen("curcubeu.out", "w", stdout);

	scanf("%d%d%d%d", &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)
		printf("%d\n", color[i]);

	return 0;

}

//Trust me, I'm the Doctor!