QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#5047. Permutacja

統計

Dana jest permutacja $p_1, p_2, \dots, p_n$. Możesz wielokrotnie wykonywać następujące operacje:

  • Wybierz przedział $p_l, p_{l+1}, \dots, p_{l+c}$ ($l \ge 1, l+c \le n$), w którym $p_l$ jest najmniejszym elementem; możesz dowolnie permutować elementy $p_{l+1}, \dots, p_{l+c}$.
  • Wybierz przedział $p_l, p_{l+1}, \dots, p_{l+c}$ ($l \ge 1, l+c \le n$), w którym $p_{l+c}$ jest najmniejszym elementem; możesz dowolnie permutować elementy $p_l, \dots, p_{l+c-1}$.

Chcesz wiedzieć, ile różnych permutacji możesz uzyskać, stosując te operacje. Wynik może być duży, więc wyprowadź go modulo 998244353.

Wejście

Pierwsza linia zawiera liczbę całkowitą $T$ oznaczającą liczbę zestawów danych ($1 \le T \le 100000$).

Pierwsza linia każdego zestawu danych zawiera dwie liczby całkowite $n$ oraz $c$ ($2 \le c \le 500000, 2 \le n \le 500000$). Suma $n$ dla wszystkich zestawów danych nie przekracza 500000.

Druga linia każdego zestawu danych zawiera permutację $p_1, \dots, p_n$ ($1 \le p_i \le n$).

Wyjście

Dla każdego zestawu danych wyprowadź w jednej linii wynik modulo 998244353.

Przykład

Wejście 1

5
5 3
3 4 2 1 5
5 4
4 2 1 3 5
5 2
4 5 3 1 2
5 3
4 3 2 1 5
5 2
2 3 1 5 4

Wyjście 1

6
1
4
6
4

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#220EditorialOpen题解jiangly2025-12-13 00:17:00View

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.