Pagini recente » Cod sursa (job #1914338) | Cod sursa (job #327142) | Cod sursa (job #1688193) | Cod sursa (job #679686) | Cod sursa (job #90381)
Cod sursa(job #90381)
// O( N )
#include <cstdio>
#define MN (1<<20)
int N, col[MN], next[MN], op[MN][3], repos[MN], rank[MN];
int find( int x )
{
if( repos[x] == x )
return x;
return repos[x] = find( repos[x] );
}
void unify( int x, int y )
{
x = find(x), y = find(y);
if( rank[x] > rank[y] ) repos[y] = x, rank[x] += rank[y];
else repos[x] = y, rank[y] += rank[x];
}
void doit( int A, int B, int C )
{
int last = -1;
for( int i = A; i <= B; i++ )
{
if( i && col[i-1] )
unify( i - 1, i );
if( !col[i] )
col[i] = C;
else
i = next[ find( i ) ];
}
next[ find(A) ] = B;
}
int main()
{
freopen("curcubeu.in", "r", stdin);
freopen("curcubeu.out", "w", stdout);
int A, B, C;
scanf("%d %d %d %d", &N, &A, &B, &C);
for( int i = 0; i < N - 1; i++ )
next[i] = i, repos[i] = i, rank[i] = 0;
for( int i = 2 ; i <= N; i++ )
{
if( A > B ){ int aux = A; A = B; B = aux; }
op[i-1][0] = A - 1, op[i-1][1] = B - 1, op[i-1][2] = C;
A = ( (long long)(A) * i ) % N,
B = ( (long long)(B) * i ) % N,
C = ( (long long)(C) * i ) % N;
}
for( int i = N - 1; i >= 1; --i )
doit( op[i][0], op[i][1], op[i][2] );
for( int i = 0; i < N - 1; i++ )
printf("%d\n", col[i]);
return 0;
}