Restaurant Recommendation Rescue

시간 제한2초메모리 제한2048 MB

문제

A certain aspiring musician K loves going for shabu-shabu! Recently, she’s been to $N$ shabushabu restaurants, numbered $1, 2, \dots , N$, following the following algorithm:

  1. K keeps an ordered list of recommendations, starting with restaurant $1$.
  2. On the $i$-th day, she visits the next recommended restaurant on her list, which recommends her restaurants $R_i = \{r_{i,1}, \dots , r_{i,ℓ_i}\}$.
  3. K appends $R_i$ to her list of restaurants to visit.
  4. K repeats steps 2-4 until she runs out of recommended restaurants.
  5. K writes down the array $A_0, \dots , A_{N−1}$, where $A_i$ equals the number of restaurants she was recommended on the $(i + 1)$-th day. That is, $A_i = |R_{i+1}|$.

It is guaranteed that $\bigcup^N_{i=1} R_i = \{2, \dots , N\}$ and $R_i ∩ R_j = ∅$ for $i \ne j$, that is, every restaurant, other than the first, will be recommended by exactly one other restaurant.

Once K finishes her list, K’s delinquent friend H decides to play a prank on her! She replaces the array $A_0, \dots , A_{N−1}$ with another array $B_0, \dots , B_{N−1}$! K thinks that this new array $B_i$ might just be a cyclic shift of her array, so she asks you to determine all possible $0 ≤ k < N$ such that $A_i = B_{(i+k) \bmod N}$, for all $0 ≤ i < N$ and any valid output of her algorithm $A_0, \dots , A_{N−1}$.

Furthermore, K will then perform $Q$ operations, where for the $i$-th operation, she swaps $B_{x_i}$, $B_{y_i}$ and asks you to do the same on the new array. Can you help K see through her friend’s prank?

입력

The first line of input will contain two integers, $N$ ($1 ≤ N ≤ 500\, 000$) and $Q$ ($0 ≤ Q ≤ 300\, 000$).

The next line of input will contain $N$ space-separated non-negative integers, $B_0, B_1, \dots , B_{N−1}$ ($0 ≤ B_i < N$), the initial sequence.

The $i$-th of the next $Q$ lines of input will contain two integers each, $x_i$ and $y_i$ ($0 ≤ x_i , y_i < N$ and $x_i \ne y_i$), indicating you are to swap $B_{x_i}$ with $B_{y_i}$ .

출력

For each of the $Q + 1$ arrays (including the initial array $B_0, \dots , B_{N−1}$), let $S = \{k_1, \dots , k_m\}$ denote the set of integers $0 ≤ k_j < N$ such that there exists a valid output $A_0, \dots , A_{N−1}$ of K’s algorithm such that $A_i = B_{(i+k_j ) \bmod N}$ for all $0 ≤ i < N$. Output, on a single line, the integers $m$ and $\sum^m_{i=1} k_i \pmod {998\, 244\, 353}$, separated by a space.

In particular, if $S = ∅$, your output should be 0 0.