問題一覧 > 通常問題

No.958 Tapris Tabel (Palindrome)

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 34
作問者 : treeone / テスター : ei1333333
お気に入りにしたユーザー ProblemId : 3600 / 自分の提出
問題文最終更新日: 2019-12-20 22:11:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2019 (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$ and an integer $K$.

Let $T$ be the string obtained by concatenating $K$ copies of $S$.

You are given $Q$ queries of the following form, so process them.

  • Find the length of the maximal palindrome centered at the $A_i$-th character of $T$.

Note:

If $T[x - i] = T[x + i]$ holds for $1\leq i\leq r$ (where $1\leq x - r \leq x + r\leq KN$), and

$T[x - r - 1] \ne T[x + r + 1]$ or $x - r = 1$ or $x + r = KN$ holds,

then $T[x - r..x + r]$ is called the maximal palindrome centered at the $x$-th character of $T$, and its length is $2r + 1$.

What is XOR

It is as follows.

Input

$N\ K\ Q$
$S$
$A_1$
$A_2$
$:$
$A_Q$
  • $S$ is a string consisting of lowercase English letters
  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq K \leq 10^9$
  • $1 \leq Q \leq 2\times 10^5$
  • $1 \leq A_i \leq KN$
  • $N, K, Q, A_i$ are integers

Output

For each query, output the answer on one line.

Sample

Sample 1
Input
17 2 2
ushitapunichiakun
17
34
Output
3
1

The maximal palindrome centered at the $17$-th character of $T$ is the underlined part below, and its length is 3.

$T =$ ushitapunichiakunushitapunichiakun

Sample 2
Input
13 3 3
abcdefgfedcba
7
20
33
Output
13
39
13

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。