#P2391. 白雪皑皑

    ID: 1384 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>模拟并查集福建省历届夏令营

白雪皑皑

Description

There are nn snowflakes arranged in a line. pty will perform mm coloring operations. In the ii-th coloring operation, he colors all snowflakes between the ((i×p+q)modn)+1((i\times p+q)\bmod n)+1-th snowflake and the ((i×q+p)modn)+1((i\times q+p)\bmod n)+1-th snowflake (inclusive) with color ii. Here p,qp, q are two given positive integers. He wants to know the final color of each of the nn snowflakes. Output 00 for any snowflake that is never colored.

Input Format

The input consists of four lines, each containing one integer, namely n,m,p,qn, m, p, q, as described above.

Output Format

Output nn lines. The ii-th line contains one integer, the color of the ii-th snowflake.

4
3
2
4
2
2
3
0

Hint

  • For 20%20\% of the testdata: n,m1000n,m\leq 1000.
  • For 40%40\% of the testdata: n8000n\leq 8000, m106m\leq 10^6.
  • For 80%80\% of the testdata: n5×105n\leq 5\times 10^5, m107m\leq 10^7.
  • For 100%100\% of the testdata: 1n1061\leq n\leq 10^6, 1m1071\leq m\leq 10^7.

It is guaranteed that 1m×p+q,m×q+p2×1091\leq m\times p+q,m\times q+p\leq 2\times 10^9.

Translated by ChatGPT 5