QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#4881. Trudny problem

Estadísticas

Dany jest ciąg liczb całkowitych $a_1, \dots, a_n$. Podciąg o parzystej długości $a_i, \dots, a_{i+2m-1}$ nazywamy dobrym, jeśli spełniony jest warunek: $|\max(a_i, \dots, a_{i+m-1}) - \max(a_{i+m}, \dots, a_{i+2m-1})| \le k$.

Zdefiniujmy ciąg liczb całkowitych $f$ w następujący sposób:

  • $f_1 = 3240$
  • $f_2 = 3081$
  • $f_3 = 2841$
  • $f_4 = 343$
  • $f_i = f_{i-1} \cdot 223 + f_{i-2} \cdot 229 + f_{i-3} \cdot f_{i-4} \cdot 239 + 17$ dla $i > 4$

Oblicz sumę $(a_{i+m-1} + 10) \cdot f_m$ dla wszystkich dobrych podciągów. Ponieważ liczba ta może być duża, wyprowadź wynik modulo $998\,244\,353$.

Wejście

Pierwsza linia zawiera jedną liczbę całkowitą $t$ ($1 \le t \le 10^4$) — liczbę zestawów danych. Następnie następuje opis zestawów danych.

Pierwsza linia każdego zestawu danych zawiera dwie liczby całkowite $n, k$ ($1 \le n \le 5 \cdot 10^5$, $0 \le k \le \min(n, 10)$).

Kolejna linia zawiera $n$ liczb całkowitych $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$).

Gwarantuje się, że suma $n$ dla wszystkich zestawów danych nie przekracza $5 \cdot 10^5$.

Wyjście

Dla każdego zestawu danych wyprowadź jedną liczbę całkowitą — odpowiedź na zadanie.

Przykład

Wejście 1

3
6 0
3 1 3 1 3 1
8 4
5 8 4 6 5 7 8 5
7 3
2 1 3 2 2 1 3

Wyjście 1

144768
745933
448953

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#626Editorial Open集训队作业 解题报告 by 陈奕帆Qingyu2026-01-02 23:20:04 Download

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.