FFT?
Time: 2 s
Memory: 500 MB
Memory: 500 MB
You are given two strings, \(s\) and \(p\), of length \(n\) and \(m\), respectively. Your task is to process \(q\) queries, each consisting of an integer \(i\) \((1 \leq i \leq n)\). For each query, you must find the number of occurrences of string \(p\) as a subsequence of \(s\) after removing the character at position \(i\) from \(s\). Each query is independent.
Input
The first line contains a single integer \(t\) \((1 \leq t \leq 10^3)\) — the number of test cases.The first line of each test case contains three integers \(n, m, q\) \((1 \leq n,m,q \leq 10^3)\) — the length of \(s\) and \(p\), and the number of queries, respectively.
The second line of each test case contains the string \(s\) of \(n\) lowercase English letters.
The third line of each test case contains the string \(p\) of \(m\) lowercase English letters.
Each of the next \(q\) lines contain an integer \(i\) \((1 \leq i \leq n)\) — described in the statement.
It is guaranteed that the sum of \(n\), \(m\) and \(q\) over all test cases doesn't exceed \(2 \cdot 10^3\).
Output
For each test case, print a \(q\) lines. The \(i\)-th of these lines should contain the result of the \(i\)-th query modulo \(998244353\).
Examples
| Input | Output |
|---|---|
|
1
5 2 5 abbab bb 1 2 3 4 5 |
3
1 1 3 1 |
Problem Info
| Problem ID | 276 |
| Time Limit | 2000 ms |
| Memory Limit | 512000 KB |
| Moderators | amirhozaifa , fahimcp495 |
Statistics
Submit
You need to Login or Registration for submit your solution