Pagini recente » Cod sursa (job #2543218) | Cod sursa (job #2523803) | Cod sursa (job #877356) | Cod sursa (job #1868235) | Cod sursa (job #3204812)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int n,m,i,j,x,y,a,b,c,st,dr,father[100005],sol[1000005];
struct s
{
int c,b,a;
}color[1000005];
int root(int nod)
{
if(father[nod] > dr )
return father[father[nod]];
int r = root(father[nod]);
father[nod] = r; //da, pierd tatal direct, dar nu conteaza
return r;
}
int main()
{
fin>>n>>a>>b>>c;
color[1].a=a , color[1].b=b , color[1].c = c;
for(i=1;i<n;i++)
father[i] = i+1;
father[n]=n;
for(i=2;i<n;i++)
{
a = color[i].a = a*i%n;
b = color[i].b = b*i%n;
c = color[i].c = c*i%n;
}
int last=n-1; //ultima operatie care se intampla
for(i=n-1;i>=1;i--)
{
st = min(color[i].a, color[i].b);
dr = max(color[i].a, color[i].b);
int j=st;
while(j<=dr)
{
while(!sol[j] && j<=dr)
{
sol[j] = color[i].c;
j++;
}
root(st);
while(sol[j] && j<=dr)
j = root(st); // de fiecare data merg pana la inceput si schimb root, ig
}
}
for(i=1; i<n;i++)
fout<<sol[i]<<'\n';
return 0;
}