Logo
(追記) (追記ここまで)

34526번 - Restaurant Recommendation Rescue 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB666100.000%

문제

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,l_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.

제한

서브태스크

번호배점제한
13

1ドル ≤ N ≤ 8,ドル $Q = 0$

27

1ドル ≤ N ≤ 5,円 000,ドル $Q = 0$

310

1ドル ≤ N ≤ 500,円 000,ドル $Q = 0$

45

1ドル ≤ N ≤ 500,円 000,ドル 0ドル ≤ Q ≤ 300,円 000$

예제 입력 1

5 3
1 2 0 0 1
0 2
1 3
3 2

예제 출력 1

1 4
1 1
1 2
1 2

The array $A$ is $[1, 1, 2, 0, 0]$; it can be shown this is the only valid output of K’s algorithm that corresponds to the array $B = [1, 2, 0, 0, 1]$. One input for K’s algorithm that yields this array $A$ is: \begin{align*}R_1 &= \{2\} \\ R_2 &= \{3\} \\R_3 &= \{4, 5\}\\ R_4 &= ∅ \\ R_5 &= ∅\text{.}\end{align*}

After swapping $B_0$ and $B_2,ドル we get the array \begin{align*}B = [0, 2, 1, 0, 1]\text{.}\end{align*}

It can be shown the only valid output of K’s algorithm that corresponds to this is \begin{align*}A = [2, 1, 0, 1, 0]\text{.}\end{align*}

One possible input to K’s algorithm that yields this array $A$ is \begin{align*}R_1 &= \{2, 3\} \\ R_2 &= \{4\}\\ R_3 &= ∅ \\ R_4 &= \{5\} \\ R_5 &= ∅\text{.}\end{align*}

노트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2025 > CCO 2025 4번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /