QOJ.ac

QOJ

时间限制: 4.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#18428. מיון

统计

נתונה תמורה $p$ באורך $n$.

כל פעולה בוחרת באקראי ובהסתברות שווה מספר שלם $i$ ($1 \le i \le n$), ולאחר מכן ממיינת את קטע הרישא $[1, i]$ ואת קטע הסיפא $[i + 1, n]$ של התמורה $p$ בסדר עולה, בהתאמה. בפרט, כאשר $i = n$, קטע הסיפא ריק, דבר השקול למיון התמורה כולה.

עליכם למצוא את תוחלת מספר הפעולות הנדרשות עד שהתמורה הסופית תהיה ממוינת לחלוטין בסדר עולה (כלומר, $p_j = j$).

יש להחזיר את התשובה מודולו $998\,244\,353$.

קלט

בעיה זו מכילה מספר מקרי בדיקה.

השורה הראשונה מכילה מספר שלם $T$ ($1 \le T \le 100$), מספר מקרי הבדיקה.

עבור כל מקרה בדיקה:

  • השורה הראשונה מכילה מספר שלם $n$ ($1 \le n \le 500$), אורך התמורה.
  • השורה השנייה מכילה $n$ מספרים שלמים $p_1, p_2, \cdots, p_n$ ($1 \le p_j \le n$), המייצגים את התמורה הנתונה $p$. מובטח כי הסדרה הנתונה היא תמורה של $1 \sim n$.

מובטח כי סכום ערכי $n$ על פני כל מקרי הבדיקה אינו עולה על $2000$.

פלט

עבור כל מקרה בדיקה, הדפיסו שורה אחת המכילה מספר שלם: תוחלת מספר הפעולות מודולו $998\,244\,353$.

דוגמה

קלט

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

פלט

748683267
2
670695427

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.