Cod sursa(job #2178739)

Utilizator flibiaVisanu Cristian flibia Data 19 martie 2018 18:14:42
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define N 1000100
#define ll long long 

using namespace std;

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

int n, a, b, c, L[N], R[N], C[N], sol[N];
set <int> h;

int main(){
	in >> n >> a >> b >> c;
	for(int i = 1; i <= n; i++){
		if(i > 1){
			a = ((ll)a * (ll)i) % n;
			b = ((ll)b * (ll)i) % n;
			c = ((ll)c * (ll)i) % n;
		}
		L[i] = max(1, min(a, b));
		R[i] = max(a, b);
		C[i] = c;
		if(i < n)
			h.insert(i);
	}
	for(int i = n - 1; i > 0 && h.size(); i--){
		auto it = h.upper_bound(L[i] - 1);
		auto it2 = h.upper_bound(R[i]);
		if(it == h.end() || *it > R[i] || *it2 < L[i])
			continue;
		auto p = it;
		while(p != it2)
			sol[*p] = C[i], p++;
		h.erase(it, it2);
	}
	for(int i = 1; i < n; i++)
		out << sol[i] << '\n';
	return 0;
}