Pagini recente » Cod sursa (job #847884) | Cod sursa (job #1428619) | Cod sursa (job #2122909) | Cod sursa (job #1462071) | Cod sursa (job #3318223)
#include "bits/stdc++.h"
using namespace std;
ifstream f ("curcubeu.in");
ofstream g ("curcubeu.out");
int t[1000002],nr[1000002],u[1000002],a[1000002],b[1000002],c[1000002],v[1000002];
int fi (int x)
{
if (t[x]==x) return x;
else
{
t[x]=fi(t[x]);
return t[x];
}
}
void un (int x,int y)
{
t[x]=fi(x);t[y]=fi(y);
if (t[x]!=t[y])
{
if (nr[t[x]]>nr[t[y]])
{
nr[t[x]]+=nr[t[y]];
t[t[y]]=t[t[x]];
u[t[y]]=max (u[t[y]],u[t[x]]);
u[t[x]]=max (u[t[x]],u[t[y]]);
}
else
{
nr[t[y]]+=nr[t[x]];
t[t[x]]=t[t[y]];
u[t[y]]=max (u[t[y]],u[t[x]]);
u[t[x]]=max (u[t[x]],u[t[y]]);
}
}
}
int main ()
{
int n,x,y,tt;
f>>n>>a[1]>>b[1]>>c[1];
for (x=2;x<n;x++)
{
a[x]=(a[x-1]*x)%n;
b[x]=(b[x-1]*x)%n;
c[x]=(c[x-1]*x)%n;
}
for (x=n-1;x>=1;x--)
{
for (y=min(a[x],b[x]);y<=max(a[x],b[x]);y++)
{
if (v[y]==0)
{
v[y]=c[x];
t[y]=y;nr[y]=1;u[y]=y;
if (v[y-1]!=0)
{
un(y-1,y);
}
if (v[y+1]!=0)
{
un (y,y+1);
}
}
else
{
tt=fi(y);
y=u[tt];
}
}
}
for (x=1;x<n;x++)
g<<v[x]<<'\n';
f.close ();
g.close ();
return 0;
}