Pagini recente » Cod sursa (job #1668232) | Cod sursa (job #2126314) | Cod sursa (job #1177935) | Cod sursa (job #1074512) | Cod sursa (job #3196570)
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
class OutParser {
private:
FILE *fout;
char *buff;
int sp;
void write_ch(char ch) {
if (sp == 50000) {
fwrite(buff, 1, 50000, fout);
sp = 0;
buff[sp++] = ch;
} else {
buff[sp++] = ch;
}
}
public:
OutParser(const char* name) {
fout = fopen(name, "w");
buff = new char[50000]();
sp = 0;
}
~OutParser() {
fwrite(buff, 1, sp, fout);
fclose(fout);
}
OutParser& operator << (int vu32) {
if (vu32 <= 9) {
write_ch(vu32 + '0');
} else {
(*this) << (vu32 / 10);
write_ch(vu32 % 10 + '0');
}
return *this;
}
OutParser& operator << (long long vu64) {
if (vu64 <= 9) {
write_ch(vu64 + '0');
} else {
(*this) << (vu64 / 10);
write_ch(vu64 % 10 + '0');
}
return *this;
}
OutParser& operator << (char ch) {
write_ch(ch);
return *this;
}
OutParser& operator << (const char *ch) {
while (*ch) {
write_ch(*ch);
++ch;
}
return *this;
}
};
const int NMAX = 1e6;
struct numere{
int a,b,c;
}v[NMAX+5];
int sar[NMAX+5],dsu[NMAX+5],h[NMAX+5],culoare[NMAX+5];
int find1(int x){
if(x==dsu[x]){return x;}
return find1(dsu[x]);
}
void union1(int x,int y){
if(h[x]>h[y]){
dsu[y]=x;
}
else if(h[y]>h[x]){
dsu[x]=y;
}
else{
dsu[y]=x;h[x]++;
}
}
int main()
{
ifstream fin("curcubeu.in");
OutParser fout("curcubeu.out");
int n;fin>>n>>v[1].a>>v[1].b>>v[1].c;
for(int i=2;i<n;i++){
v[i].a=(1LL*v[i-1].a*i)%n;
v[i].b=(1LL*v[i-1].b*i)%n;
v[i].c=(1LL*v[i-1].c*i)%n;
}
for(int i=1;i<n;i++){
dsu[i]=i;h[i]=1;sar[i]=i+1;
}
for(int i=n-1;i>=1;i--){
int st=min(v[i].a,v[i].b),dr=max(v[i].a,v[i].b);
int poz=st;
while(poz<=dr){
if(culoare[poz]==0){culoare[poz]=v[i].c;}
int nr1=find1(st),nr2=find1(poz);
int poz1=sar[nr2];
if(nr1!=nr2){
union1(nr1,nr2);
}
poz=poz1;
}
sar[st]=dr+1;
}
for(int i=1;i<n;i++){
fout<<culoare[i]<<'\n';
}
return 0;
}