Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

給定整數 $N, K$ 以及一個長度為 $Q$ 的整數序列 $D = (D_1, D_2, \dots, D_Q)$。

對於一個 $(1, 2, \dots, N)$ 的排列 $P = (P_1, P_2, \dots, P_N)$,我們定義一個包含頂點 $1, 2, \dots, N$ 的無向圖 $G(P)$ 如下:

對於每對滿足 $1 \le i < j \le N$ 的整數 $(i, j)$,當且僅當 $P_i > P_j$ 時,在 $G(P)$ 中頂點 $i$ 和 $j$ 之間存在一條邊。

對於每個 $d = 1, 2, \dots, N - 1$,令 $\mathcal{S}_d$ 為滿足以下所有條件的 $(1, 2, \dots, N)$ 的排列 $P$ 的集合:

  • $G(P)$ 是一棵樹。
  • $G(P)$ 的直徑為 $d$。

對於每個查詢 $q = 1, 2, \dots, Q$,計算

$$\sum_{P \in \mathcal{S}_{D_q}} (\text{LIS}(P))^K \bmod 998244353,$$

其中 $\text{LIS}(P)$ 表示 $P$ 的最長遞增子序列的長度。

輸入格式

輸入從標準輸入按以下格式給出:

N K
Q
D_1
D_2
:
D_Q
  • 所有輸入值均為整數。
  • $2 \le N \le 10^6$
  • $0 \le K \le 10^{18}$
  • $1 \le Q \le 2 \times 10^5$
  • $1 \le D_1 < D_2 < \dots < D_Q < N$

輸出格式

依次輸出 $Q$ 行。

第 $q$ 行應包含第 $q$ 個查詢的答案。

範例

範例輸入 1

4 0
3
1
2
3

範例輸出 1

0
2
2

範例輸入 2

2 100
1
1

範例輸出 2

1

範例輸入 3

314159 26535
5
271
828
1828
45904
52353

範例輸出 3

765557189
351184939
258247317
305813889
68486796

說明

在第一個範例中,使得 $G(P)$ 是一棵樹的 $(1, 2, 3, 4)$ 的排列 $P$ 恰好有以下 $4$ 個:

  • $P = (2, 3, 4, 1)$:$G(P)$ 的直徑為 $2$,且 $\text{LIS}(P) = 3$。
  • $P = (4, 1, 2, 3)$:$G(P)$ 的直徑為 $2$,且 $\text{LIS}(P) = 3$。
  • $P = (2, 4, 1, 3)$:$G(P)$ 的直徑為 $3$,且 $\text{LIS}(P) = 2$。
  • $P = (3, 1, 4, 2)$:$G(P)$ 的直徑為 $3$,且 $\text{LIS}(P) = 2$。

因此:

  • 對於 $q = 1$,答案為 $0$。
  • 對於 $q = 2$,答案為 $3^0 + 3^0 = 2$。
  • 對於 $q = 3$,答案為 $2^0 + 2^0 = 2$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1413EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.