Description
Input
第一行四个正整数N,M,p,q
Output
一共输出N行,第i行表示第i个馒头的最终颜色(如果最终颜色是白色就输出0)。
Sample Input
4 3 2 4
Sample Output
2
2
3
0
HINT
Source
冰茶几的小应用
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 1000010
#define GET (ch>='0'&&ch<='9')
using namespace std;
int n,m,p,q;
int c[MAXN],f[MAXN];
int find(int x) { return (f[x]==x||!f[x])?f[x]=x:f[x]=find(f[x]); }
int main()
{
for (scanf("%d%d%d%d",&n,&m,&p,&q);m;m--)
{
int i=m,l=((long long)(i*p)+q)%n+1,r=((long long)(i*q)+p)%n+1;
if (l>r) swap(l,r);
for (int j=find(l);j<=r;j=find(j)) c[j]=i,f[j]=j+1;
}
for (int i=1;i<=n;i++) printf("%d\n",c[i]);
}