Pagini recente » Cod sursa (job #632287) | Cod sursa (job #766459) | Cod sursa (job #1456664) | Cod sursa (job #1364545) | Cod sursa (job #2225797)
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000005], b[1000005], c[1000005];
int t[1000005], nxt[1000005];
int ans[1000005];
inline int f(int x) {
int y = x;
while (x != t[x])
x = t[x];
while (y != t[y]) {
int aux = t[y];
t[y] = x;
y = aux;
}
return x;
}
inline void u(int x, int y) {
x = f(x);
y = f(y);
if (x == y)
return ;
t[y] = x;
nxt[x] = max(nxt[x], nxt[y]);
}
int get(int x) {
return nxt[f(x)];
}
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;
}
};
int main() {
freopen("curcubeu.in", "r", stdin);
OutParser out("curcubeu.out");
int n, x, y;
scanf("%d", &n);
scanf("%d%d%d", &a[1], &b[1], &c[1]);
t[1] = 1;
nxt[1] = 2;
for (int i = 2; i < n; ++i) {
a[i] = 1LL * a[i - 1] * i % n;
b[i] = 1LL * b[i - 1] * i % n;
c[i] = 1LL * c[i - 1] * i % n;
t[i] = i;
nxt[i] = i + 1;
}
for (int i = n - 1; i >= 1; --i) {
x = min(a[i], b[i]);
y = a[i] ^ b[i] ^ x;
if (ans[x] != 0)
x = get(x);
for (int j = x; j <= y; j = get(j)) {
ans[j] = c[i];
if (ans[j - 1] != 0)
u(j - 1, j);
if (ans[j + 1] != 0)
u(j + 1, j);
}
}
for (int i = 1; i < n; ++i)
out << ans[i] << '\n';
return 0;
}