Pagini recente » Cod sursa (job #2565460) | Cod sursa (job #3162380) | Cod sursa (job #86512) | Cod sursa (job #1371751) | Cod sursa (job #2254853)
#include <bits/stdc++.h>
#define MaxN 1000005
#define ll long long
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;
}
};
std::ifstream InFile("curcubeu.in");
OutParser OutFile("curcubeu.out");
ll N, A[MaxN], B[MaxN], C[MaxN],
Next[MaxN], Color[MaxN];
void Citire() {
InFile >> N >> A[1] >> B[1] >> C[1];
for (int i=1; i<N-1; ++i)
A[i+1] = (A[i]*(i+1)) % N,
B[i+1] = (B[i]*(i+1)) % N,
C[i+1] = (C[i]*(i+1)) % N;
}
void Rezolvare() {
ll a, b;
for (int i=0; i<N; ++i)
Next[i] = i;
for (int i=N, j; i>0; --i) {
a = A[i-1], b = B[i-1];
if(A[i-1] > B[i-1])
std::swap(a, b);
for (j=a; j<=b; ++j)
if (!Color[j])
Color[j] = C[i-1],
Next[j] = b+1; // !!! Compresia
else j = Next[j]-1;
}
for (int i=0; i<N-1; ++i)
OutFile << Color[i+1] << '\n';
}
int main() {
Citire();
Rezolvare();
return 0;
}