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 k and q are smaller. You can hack only if you solved all versions of this problem.
Define popcountk(m) as the sum of all digits of m in base k.
Define a base-k integer s=s1s2⋯ of infinite length, where the i-th digit of s is si=(popcountk(i)modk).
There are q queries. Each query consists of three integers l, r, and n (all of them are given in decimal form), as well as a base-k integer t with n digits. Note that t may have leading zeros. Consider t as a string, and your task is to find the number of occurrences of t in the string slsl+1…sr.
For digits greater than or equal to decimal 10, uppercase and lowercase letters are used. Specifically, the uppercase letters A,B,…,Z represent the decimal values 10,11,…,35, and the lowercase letters a,b,…,z represent the decimal values 36,37,…,61.
这是该问题的简单版本。两个版本的区别在于,本版本中 k 和 q 的约束更小。仅当您解决了该问题的所有版本时,才允许进行 hack。
定义 popcountk(m) 为 m 在 k 进制下的各位数字之和。
定义一个长度无限的 k 进制整数 s=s1s2⋯,其中 s 的第 i 位数字为 si=(popcountk(i)modk)。
共有 q 个查询。每个查询包含三个整数 l、r 和 n(均以十进制给出),以及一个长度为 n 的 k 进制整数 t。注意:t 可能含有前导零。将 t 视为一个字符串,您的任务是求出 t 在字符串 slsl+1…sr 中出现的次数。
对于大于等于十进制 10 的数字,使用大写和小写字母表示。具体而言,大写字母 A,B,…,Z 分别表示十进制数值 10,11,…,35,小写字母 a,b,…,z 分别表示十进制数值 36,37,…,61。
输入格式
The first line of the input contains two integers k and q (2≤k≤10, 1≤q≤1000) — the base and the number of queries.
Each query contains two lines. The first line contains the three integers l, r, and n (1≤l≤r≤1017, 1≤n≤2⋅106).
The second line contains the base-k integer t with n digits (ti∈0,1,…,9,A,B,…,Z,a,b,…,z).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅106.
输入的第一行包含两个整数 k 和 q(2≤k≤10,1≤q≤1000)—— 分别表示进制基数和查询次数。
每个查询包含两行。第一行包含三个整数 l、r 和 n(1≤l≤r≤1017,1≤n≤2⋅106)。
第二行包含一个长度为 n 的 k 进制整数 t(其各位数字 ti 属于集合 {0,1,…,9,A,B,…,Z,a,b,…,z})。
保证所有测试用例中 n 的总和不超过 2⋅106。
输出格式
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…sr as s[l;r].
In the first example, k=3, s=12120201120201012201120012…, s[5;17]=0201120201012, and t=201 appears a total of 2 times in s[5;17]. Their indices in the string s are s[6;8] and s[12;14]. And t=01 appears 3 times. Their indices in the string s are s[7;8], s[13;14], and s[15;16].
For the second example, k=10, s[1;20]=12345678912345678902, and t=123456789 appears a total of 2 times in s[1;20].
记字符串 slsl+1…sr 为 s[l;r]。
在第一个例子中,k=3,s=12120201120201012201120012…,s[5;17]=0201120201012,而 t=201 在 s[5;17] 中共出现 2 次,其在字符串 s 中的起始位置分别为 s[6;8] 和 s[12;14];而 t=01 共出现 3 次,其在字符串 s 中的起始位置分别为 s[7;8]、s[13;14] 和 s[15;16]。
在第二个例子中,k=10,s[1;20]=12345678912345678902,而 t=123456789 在 s[1;20] 中共出现 2 次。
输入解题思路,AI测评打分。不知道怎么写?