Pagini recente » Cod sursa (job #2278702) | Cod sursa (job #2650817) | Cod sursa (job #2142934) | Cod sursa (job #3266073) | Cod sursa (job #2187359)
#include <iostream>
#include <fstream>
#define nmax 1000002
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int a[nmax],b[nmax],c[nmax],st,dr,poz,t[nmax],n,v[nmax];
bool painted[nmax];
int maxim(int a, int b)
{
if(a>b) return a;
return b;
}
int minim(int a, int b)
{
if(a<b) return a;
return b;
}
int gaseste(int x)
{
int z,rx;
rx=x;
while(rx!=t[rx])
rx=t[rx];
while(rx!=x)
{
z=t[x];
t[x]=rx;
x=z;
}
return rx;
}
void Union(int a, int b)
{
a=gaseste(a);
b=gaseste(b);
if(a==b) return;
t[b]=a;
}
inline int init(int t[])
{
for(int i =1 ; i <= n ; i++)
t[i]=i;
}
void rainbow(int st, int dr, int culoare)
{
int poz=st;
while(poz<=dr)
{
if(!v[poz])
{
v[poz]=culoare;
painted[poz]=1;
if(poz>2)
if(painted[poz-1])
Union(poz-1,poz);
if(poz<n)
if(painted[poz+1])
Union(poz,poz+1);
poz++;
}
else
poz=gaseste(poz)+1;
}
}
int main()
{
fin>>n>>a[1]>>b[1]>>c[1];
for(int i =2 ; i < n ; i++)
{
a[i]=(a[i-1]*i)%n;
b[i]=(b[i-1]*i)%n;
c[i]=(c[i-1]*i)%n;
}
init(t);
for(int i = n - 1 ; i >= 1; i--)
{
rainbow(minim(a[i],b[i]),maxim(a[i],b[i]),c[i]);
}
for(int i =1 ; i < n ; i++)
fout<<v[i]<<'\n';
return 0;
}