类似与链表那样搞一搞就可以了。
注意有可能跑到第n + 1个点,于是也要给这个点赋个father。
/* Telekinetic Forest Guard */
#include <cstdio>
#include <algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1000005;
int n, m, p, q, fa[maxn], res[maxn];
inline int iread() {
int f = 1, x = 0; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return f * x;
}
inline int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
n = iread(); m = iread(); p = iread(); q = iread();
for(int i = n + 1; i; i--) fa[i] = i;
for(int i = m; i; i--) {
int l = (i * p + q) % n + 1, r = (i * q + p) % n + 1;
if(l > r) swap(l, r);
for(int x = find(l); x <= r; x = find(x)) res[x] = i, fa[x] = x + 1;
}
for(int i = 1; i <= n; i++) printf("%d\n", res[i]);
return 0;
}