Logo
(追記) (追記ここまで)

18658번 - Square Substrings 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 512 MB3322327.273%

문제

Bob has a string s1s2 · · · sn and q queries (li, ri) (i = 1, 2, . . . , q). For each query (li, ri), he would like to know the number of intervals (L, R) such that li ≤ L ≤ R ≤ ri and sLsL+1 · · · sR is a square. Could you please help him?

A string t1t2 · · ·tm is a square if and only if:

  • m is even;
  • ti = ti+m/2 for i = 1, 2, . . . , m/2.

입력

The input contains several test cases. The first line contains an integer T indicating the number of test cases. The following describes all test cases. For each test case:

The first line contains two integers n and q.

The second line contains a string of n lowercase letters, s1s2 · · · sn.

The i-th one of the following q lines contains two integers li and ri, representing a query.

출력

For each test case, firstly output a line containing “Case #x:” (without quotes), where x is the test case number starting from 1.

Then, for each query, output a line containing an integer, denoting the answer to this query.

제한

  • 1 ≤ T ≤ 100
  • 1 ≤ n, q ≤ 106
  • 1 ≤ li ≤ ri ≤ n
  • The sum of n in all test cases does not exceed 106.
  • The sum of q in all test cases does not exceed 106.

예제 입력 1

1
7 5
ababbab
1 4
2 5
3 6
4 7
1 7

예제 출력 1

Case #1:
1
1
1
1
3

힌트

bb, abab and babbab are squares, while abba is not a square.

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 8: Jingzhe Tang Contest 2, XIX Open Cup Onsite J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /