CF2249E1.String (Easy Version)

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, the constraints on kk and qq are smaller. You can hack only if you solved all versions of this problem.

Define popcountk(m)\mathrm{popcount}_k(m) as the sum of all digits of mm in base kk.

Define a base-kk integer s=s1s2⋯‾s=\overline{s_1s_2\cdots} of infinite length, where the ii-th digit of ss is si=(popcountk(i) mod k)s_i=(\mathrm{popcount}_k(i) \bmod k).

There are qq queries. Each query consists of three integers ll, rr, and nn (all of them are given in decimal form), as well as a base-kk integer tt with nn digits. Note that tt may have leading zeros. Consider tt as a string, and your task is to find the number of occurrences of tt in the string slsl+1…srs_ls_{l+1}\ldots s_r.

For digits greater than or equal to decimal 10\mathtt{10}, uppercase and lowercase letters are used. Specifically, the uppercase letters A,B,…,Z{\mathtt{A, B,\ldots,Z}} represent the decimal values 10,11,…,35{\mathtt{10, 11,\ldots,35}}, and the lowercase letters a,b,…,z{\mathtt{a, b,\ldots,z}} represent the decimal values 36,37,…,61{\mathtt{36, 37,\ldots,61}}.

这是该问题的简单版本。两个版本的区别在于,本版本中 kk 和 qq 的约束更小。仅当您解决了该问题的所有版本时,才允许进行 hack。

定义 popcountk(m)\mathrm{popcount}_k(m) 为 mm 在 kk 进制下的各位数字之和。

定义一个长度无限的 kk 进制整数 s=s1s2⋯‾s=\overline{s_1s_2\cdots},其中 ss 的第 ii 位数字为 si=(popcountk(i) mod k)s_i=(\mathrm{popcount}_k(i) \bmod k)。

共有 qq 个查询。每个查询包含三个整数 ll、rr 和 nn(均以十进制给出),以及一个长度为 nn 的 kk 进制整数 tt。注意:tt 可能含有前导零。将 tt 视为一个字符串,您的任务是求出 tt 在字符串 slsl+1…srs_ls_{l+1}\ldots s_r 中出现的次数。

对于大于等于十进制 10\mathtt{10} 的数字,使用大写和小写字母表示。具体而言,大写字母 A,B,…,Z{\mathtt{A, B,\ldots,Z}} 分别表示十进制数值 10,11,…,35{\mathtt{10, 11,\ldots,35}},小写字母 a,b,…,z{\mathtt{a, b,\ldots,z}} 分别表示十进制数值 36,37,…,61{\mathtt{36, 37,\ldots,61}}。

输入格式

The first line of the input contains two integers kk and qq (2≤k≤102\le k\le 10, 1≤q≤10001\le q\le 1000) — the base and the number of queries.

Each query contains two lines. The first line contains the three integers ll, rr, and nn (1≤l≤r≤10171\le l\le r\le 10^{17}, 1≤n≤2⋅1061\le n\le 2\cdot 10^6).

The second line contains the base-kk integer tt with nn digits (ti∈0,1,…,9,A,B,…,Z,a,b,…,zt_i\in{\mathtt{0,1,\ldots,9,A,B,\ldots,Z,a,b,\ldots,z}}).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1062 \cdot 10^6.

输入的第一行包含两个整数 kk 和 qq(2≤k≤102\le k\le 10,1≤q≤10001\le q\le 1000)—— 分别表示进制基数和查询次数。

每个查询包含两行。第一行包含三个整数 ll、rr 和 nn(1≤l≤r≤10171\le l\le r\le 10^{17},1≤n≤2⋅1061\le n\le 2\cdot 10^6)。

第二行包含一个长度为 nn 的 kk 进制整数 tt(其各位数字 tit_i 属于集合 {0,1,…,9,A,B,…,Z,a,b,…,z}\{\mathtt{0,1,\ldots,9,A,B,\ldots,Z,a,b,\ldots,z}\})。

保证所有测试用例中 nn 的总和不超过 2⋅1062 \cdot 10^6。

输出格式

For each query, output a single integer — the answer to the query.

对于每个查询,输出一个整数——该查询的答案。

输入输出样例

  • 输入#1

    3 4
    5 17 3
    201
    5 17 2
    01
    1239 1231231209 5
    01201
    123002 231203 4
    1202

    输出#1

    2
    3
    21046666
    8325
  • 输入#2

    10 3
    1 20 9
    123456789
    15 20332 3
    678
    1234 56789 2
    01

    输出#2

    2
    1625
    5000

说明/提示

Denote the string slsl+1…srs_ls_{l+1}\ldots s_r as s[l;r]s[l;r].

In the first example, k=3k = 3, s=12120201120201012201120012…s = \mathtt{12120201120201012201120012\ldots}, s[5;17]=0201120201012s[5;17] = \mathtt{0201120201012}, and t=201t = \mathtt{201} appears a total of 22 times in s[5;17]s[5; 17]. Their indices in the string ss are s[6;8]s[6; 8] and s[12;14]s[12; 14]. And t=01t = \mathtt{01} appears 33 times. Their indices in the string ss are s[7;8]s[7;8], s[13;14]s[13;14], and s[15;16]s[15;16].

For the second example, k=10k=10, s[1;20]=12345678912345678902s[1;20] = \mathtt{12345678912345678902}, and t=123456789t = \mathtt{123456789} appears a total of 22 times in s[1;20]s[1;20].

记字符串 slsl+1…srs_ls_{l+1}\ldots s_r 为 s[l;r]s[l;r]。

在第一个例子中,k=3k = 3,s=12120201120201012201120012…s = \mathtt{12120201120201012201120012\ldots},s[5;17]=0201120201012s[5;17] = \mathtt{0201120201012},而 t=201t = \mathtt{201} 在 s[5;17]s[5; 17] 中共出现 22 次,其在字符串 ss 中的起始位置分别为 s[6;8]s[6; 8] 和 s[12;14]s[12; 14];而 t=01t = \mathtt{01} 共出现 33 次,其在字符串 ss 中的起始位置分别为 s[7;8]s[7;8]、s[13;14]s[13;14] 和 s[15;16]s[15;16]。

在第二个例子中,k=10k=10,s[1;20]=12345678912345678902s[1;20] = \mathtt{12345678912345678902},而 t=123456789t = \mathtt{123456789} 在 s[1;20]s[1;20] 中共出现 22 次。

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

首页