Pagini recente » Cod sursa (job #3360395) | Cod sursa (job #3358389) | Cod sursa (job #3360391) | Cod sursa (job #3360219) | Cod sursa (job #3360220)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 - 1;
int a[MAXN] , b[MAXN] , c[MAXN] , cas[MAXN] , tat[MAXN] = { -1 };
int rad ( int x ) {
if ( tat[x] == -1 )
return x;
tat[x] = rad ( tat[x] );
return tat[x];
}
void join ( int x , int y ) {
x = rad ( x );
y = rad ( y );
if ( x != y )
tat[x] = y;
}
int main () {
ifstream fin ( "curcubeu.in" );
ofstream fout ( "curcubeu.out" );
int n , i , j , jc;
fin >> n >> a[0] >> b[0] >> c[0];
for ( i = 1 ; i < n - 1 ; i++ ) {
a[i] = ( long long ) a[i - 1] * ( i + 1 ) % n;
b[i] = ( long long ) b[i - 1] * ( i + 1 ) % n;
c[i] = ( long long ) c[i - 1] * ( i + 1 ) % n;
tat[i] = -1;
}
tat[n - 1] = -1;
for ( i = n - 2 ; i >= 0 ; i-- ) {
j = min ( a[i] , b[i] ) - 1;
while ( j + 1 <= max ( a[i] , b[i] ) ) {
jc = j;
while ( jc + 1 <= max ( a[i] , b[i] ) && !cas[jc] )
jc++;
jc--;
while ( j + 1 <= max ( a[i] , b[i] ) && !cas[j] ) {
cas[j] = c[i];
join ( j , jc );
j++;
}
j = rad ( j ) + 1;
}
}
for ( i = 0 ; i < n - 1 ; i++ )
fout << cas[i] << '\n';
return 0;
}