Pagini recente » Istoria paginii runda/rar9/clasament | Cod sursa (job #1152596) | Cod sursa (job #3031926) | Cod sursa (job #1577003) | Cod sursa (job #2224710)
#include <bits/stdc++.h>
using namespace std;
int a[1000005], b[1000005], c[1000005];
int t[1000005], h[1000005], nxt[1000005];
int ans[1000005];
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;
}
void u(int x, int y) {
x = f(x);
y = f(y);
if (x == y)
return ;
if (h[x] > h[y]) {
t[y] = x;
nxt[x] = max(nxt[x], nxt[y]);
} else if (h[x] == h[y]) {
t[y] = x;
h[x]++;
nxt[x] = max(nxt[x], nxt[y]);
} else {
t[x] = y;
nxt[y] = max(nxt[x], nxt[y]);
}
}
int get(int x) {
return nxt[f(x)];
}
int main() {
freopen("curcubeu.in", "r", stdin);
freopen("curcubeu.out", "w", stdout);
int n;
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) {
int x = min(a[i], b[i]);
int y = max(a[i], b[i]);
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)
printf("%d\n", ans[i]);
return 0;
}