AtCoder Regular Contest 160
F
Count Sorted Arrays
AtCoder
⌀ 3202
原题
← E→
翻译中…

Problem Statement

翻译中…

There are an integer $N$ and $M$ pairs of integers: $(a_1, b_1), (a_2, b_2), \dots, (a_M, b_M)$. Each pair $(a_i, b_i)$ satisfies $1 \leq a_i \lt b_i \leq N$.

翻译中…

Initally, you have all $N!$ permutations of $(1,2,\dots,N)$. You will perform $M$ operations. The $i$-th operation is as follows.

翻译中…
  • Do the following for each of your $N!$ permutations.
  • Compare the $a_i$-th and $b_i$-th elements. If the former is greater, swap the two elements.
翻译中…

For each $1 \leq i \leq M$, let $S_i$ be the number of permutations of yours that are already sorted in ascending order at the end of the $i$-th operation. Print $S_1, S_2, \dots, S_M$.

翻译中…

Here, the input gives you pairs of integers $(x_i, y_i)$ instead of $(a_i, b_i)$. The values of $(a_i, b_i)$ can be obtained using $x_i$, $y_i$, and $S_{i-1}$ as follows. (Let $S_0 = 1$ for convenience.)

翻译中…
  • Let $c_i = ((x_i + S_{i-1}) \bmod N) + 1$.
  • Let $d_i = ((y_i + S_{i-1} \times 2) \bmod N) + 1$. (Here, it is guaranteed that $c_i \neq d_i$.)
  • Let $a_i = \min(c_i, d_i)$.
  • Let $b_i = \max(c_i, d_i)$.
翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 15$
  • $1 \leq M \leq 5 \times 10^5$
  • $1 \leq a_i \lt b_i \leq N$
  • $0 \leq x_i, y_i \leq N - 1$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
x_1 y_1
x_2 y_2
\vdots
x_M y_M

翻译中…

Output

翻译中…

Print $M$ lines. The $i$-th line should contain $S_i$.

翻译中…

样例

Input #1
2 1
1 1
Output #1
2
You start with the permutations $(1, 2)$ and $(2, 1)$. We have $(a_1, b_1) = (1, 2)$. At the end of the first operation, you have two copies of $(1, 2)$, so you should print $2$.
Input #2
3 4
0 1
2 1
1 1
0 1
Output #2
2
4
4
6
$(a_i, b_i)$ in order are $(1, 2), (2, 3), (1, 3), (1, 2)$.
Input #3
5 5
4 4
0 4
1 1
2 4
1 2
Output #3
2
4
4
8
16
$(a_i, b_i)$ in order are $(1, 2), (3, 4), (1, 5), (2, 3), (4, 5)$.
题目信息
题号
arc160_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。