CF1217C.The Number Of Good Substrings

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a binary string ss (recall that a string is binary if each character is either 00 or 11).

Let f(t)f(t) be the decimal representation of integer tt written in binary form (possibly with leading zeroes). For example f(011)=3,f(00101)=5,f(00001)=1,f(10)=2,f(000)=0f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0 and f(000100)=4f(000100) = 4.

The substring sl,sl+1,…,srs_{l}, s_{l+1}, \dots , s_{r} is good if r−l+1=f(sl…sr)r - l + 1 = f(s_l \dots s_r).

For example string s=1011s = 1011 has 55 good substrings: s1…s1=1s_1 \dots s_1 = 1, s3…s3=1s_3 \dots s_3 = 1, s4…s4=1s_4 \dots s_4 = 1, s1…s2=10s_1 \dots s_2 = 10 and s2…s4=011s_2 \dots s_4 = 011.

Your task is to calculate the number of good substrings of string ss.

You have to answer tt independent queries.

给你一个二进制字符串 ss(回忆一下,若字符串中每个字符均为 00 或 11,则称该字符串为二进制字符串)。

令 f(t)f(t) 表示将整数 tt 以二进制形式(允许有前导零)写出后所对应的十进制数值。例如:f(011)=3f(011) = 3,f(00101)=5f(00101) = 5,f(00001)=1f(00001) = 1,f(10)=2f(10) = 2,f(000)=0f(000) = 0,以及 f(000100)=4f(000100) = 4。

子串 sl,sl+1,…,srs_{l}, s_{l+1}, \dots , s_{r} 被称为好子串,当且仅当其长度满足 r−l+1=f(sl…sr)r - l + 1 = f(s_l \dots s_r)。

例如,字符串 s=1011s = 1011 共有 55 个好子串:s1…s1=1s_1 \dots s_1 = 1,s3…s3=1s_3 \dots s_3 = 1,s4…s4=1s_4 \dots s_4 = 1,s1…s2=10s_1 \dots s_2 = 10,以及 s2…s4=011s_2 \dots s_4 = 011。

你的任务是计算字符串 ss 中好子串的个数。

你需要回答 tt 个相互独立的查询。

输入格式

The first line contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of queries.

The only line of each query contains string ss (1≤∣s∣≤2⋅1051 \le |s| \le 2 \cdot 10^5), consisting of only digits 00 and 11.

It is guaranteed that ∑i=1t∣si∣≤2⋅105\sum\limits_{i=1}^{t} |s_i| \le 2 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示查询次数。

每个查询仅有一行,包含一个字符串 ss(1≤∣s∣≤2⋅1051 \le |s| \le 2 \cdot 10^5),该字符串仅由数字 00 和 11 组成。

保证 ∑i=1t∣si∣≤2⋅105\sum\limits_{i=1}^{t} |s_i| \le 2 \cdot 10^5。

输出格式

For each query print one integer — the number of good substrings of string ss.

对于每个查询,输出一个整数——字符串 ss 中“好”子串的数量。

输入输出样例

  • 输入#1

    4
    0110
    0101
    00001000
    0001000

    输出#1

    4
    3
    4
    3

输入解题思路,AI测评打分。不知道怎么写?

首页