CF1729F.Kirei and the Linear Function

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given the string ss of decimal digits (0-9) of length nn.

A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of indexes (l,rl, r), where 1≤l≤r≤n1 \le l \le r \le n, corresponds to a substring of the string ss. We will define as v(l,r)v(l,r) the numeric value of the corresponding substring (leading zeros are allowed in it).

For example, if n=7n=7, s=s="1003004", then v(1,3)=100v(1,3)=100, v(2,3)=0v(2,3)=0 and v(2,7)=3004v(2,7)=3004.

You are given nn, ss and an integer ww (1≤w<n1 \le w \lt n).

You need to process mm queries, each of which is characterized by 33 numbers li,ri,kil_i, r_i, k_i (1≤li≤ri≤n;0≤ki≤81 \le l_i \le r_i \le n; 0 \le k_i \le 8).

The answer to the iith query is such a pair of substrings of length ww that if we denote them as (L1,L1+w−1)(L_1, L_1+w-1) and (L2,L2+w−1)(L_2, L_2+w-1), then:

  • L1≠L2L_1 \ne L_2, that is, the substrings are different;
  • the remainder of dividing a number v(L1,L1+w−1)⋅v(li,ri)+v(L2,L2+w−1)v(L_1, L_1+w-1) \cdot v(l_i, r_i) + v(L_2, L_2 + w - 1) by 99 is equal to kik_i.

If there are many matching substring pairs, then find a pair where L1L_1 is as small as possible. If there are many matching pairs in this case, then minimize L2L_2.

Note that the answer may not exist.

给定一个长度为 nn 的十进制数字字符串 ss(字符为 0–9)。

子串是指字符串中连续的一段字符。该字符串的一个子串由其左右端点的下标对唯一确定。因此,每一对下标 (l,r)(l, r)(满足 1≤l≤r≤n1 \le l \le r \le n)对应字符串 ss 的一个子串。我们记 v(l,r)v(l,r) 为该子串所表示的数值(允许前导零)。

例如,若 n=7n=7,s=s="1003004",则 v(1,3)=100v(1,3)=100,v(2,3)=0v(2,3)=0,v(2,7)=3004v(2,7)=3004。

你将获得 nn、ss 和一个整数 ww(1≤w<n1 \le w \lt n)。

你需要处理 mm 个查询,每个查询由三个整数 li,ri,kil_i, r_i, k_i 描述(满足 1≤li≤ri≤n1 \le l_i \le r_i \le n;0≤ki≤80 \le k_i \le 8)。

第 ii 个查询的答案是一对长度均为 ww 的子串,记作 (L1,L1+w−1)(L_1, L_1+w-1) 和 (L2,L2+w−1)(L_2, L_2+w-1),满足:

  • L1≠L2L_1 \ne L_2,即这两个子串位置不同;
  • 数值 v(L1,L1+w−1)⋅v(li,ri)+v(L2,L2+w−1)v(L_1, L_1+w-1) \cdot v(l_i, r_i) + v(L_2, L_2 + w - 1) 除以 99 的余数等于 kik_i。

若存在多组满足条件的子串对,则选择其中 L1L_1 最小的一组;若仍有多个,则在这些中选择 L2L_2 最小的一组。

注意:答案可能不存在。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — number of input test cases.

The first line of each test case contains a string ss, which contains only the characters 0-9 and has a length nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

The second line contains two integers w,mw, m (1≤w<n,1≤m≤2⋅1051 \le w \lt n, 1 \le m \le 2 \cdot 10^5), where nn — is the length of the given string ss. The number ww denotes the lengths of the substrings being searched for, and mm is the number of queries to be processed.

The following mm lines contain integers li,ri,kil_i, r_i, k_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, 0≤ki≤80 \le k_i \le 8) — iith query parameters.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5. It is also guaranteed that the sum of mm over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入测试用例的数量。

每个测试用例的第一行包含一个字符串 ss,该字符串仅由字符 0–9 组成,长度为 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)。

第二行包含两个整数 w,mw, m(1≤w<n, 1≤m≤2⋅1051 \le w \lt n,\ 1 \le m \le 2 \cdot 10^5),其中 nn 是给定字符串 ss 的长度。数值 ww 表示所查找子串的长度,mm 表示需处理的查询数量。

接下来的 mm 行每行包含三个整数 li,ri,kil_i, r_i, k_i(1≤li≤ri≤n, 0≤ki≤81 \le l_i \le r_i \le n,\ 0 \le k_i \le 8)—— 第 ii 个查询的参数。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。同时保证所有测试用例中 mm 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each request, print in a separate line:

  • left borders of the required substrings: L1L_1 and L2L_2;
  • -1 -1 otherwise, if there is no solution.

If there are several solutions, minimize L1L_1 first, and minimize L2L_2 second.

对于每个查询,在单独一行中输出:

  • 所需子串的左边界:L1L_1 和 L2L_2;
  • 若无解,则输出 -1 -1。

若存在多个解,优先最小化 L1L_1,其次最小化 L2L_2。

输入输出样例

  • 输入#1

    5
    1003004
    4 1
    1 2 1
    179572007
    4 2
    2 7 3
    2 7 4
    111
    2 1
    2 2 6
    0000
    1 2
    1 4 0
    1 4 1
    484
    1 5
    2 2 0
    2 3 7
    1 2 5
    3 3 8
    2 2 6

    输出#1

    2 4
    1 5
    1 2
    -1 -1
    1 2
    -1 -1
    1 3
    1 3
    -1 -1
    -1 -1
    -1 -1

说明/提示

Consider the first test case of example inputs. In this test case n=7n=7, s=s="1003004", w=4w=4 and one query l1=1l_1=1, r1=2r_1=2, k1=1k_1=1. Note that v(1,2)=10v(1,2)=10. We need to find a pair of substrings of length 44 such that v(L1,L1+3)⋅10+v(L2,L2+3)v(L_1, L_1+3)\cdot10+v(L_2,L_2+3) has a remainder of k1=1k_1=1 when divided by 99. The values L1=2,L2=4L_1=2, L_2=4 actually satisfy all the requirements: v(L1,L1+w−1)=v(2,5)=30v(L_1, L_1+w-1)=v(2,5)=30, v(L2,L2+w−1)=v(4,7)=3004v(L_2, L_2+w-1)=v(4,7)=3004. Indeed, 30⋅10+3004=330430\cdot10+3004=3304, which has a remainder of 11 when divided by 99. It can be shown that L1=2L_1=2 is the minimum possible value, and L2=4L_2=4 is the minimum possible with L1=2L_1=2.

考虑示例输入的第一个测试用例。在此测试用例中,n=7n=7,s=s="1003004",w=4w=4,且有一个查询:l1=1l_1=1,r1=2r_1=2,k1=1k_1=1。注意 v(1,2)=10v(1,2)=10。我们需要找到一对长度为 44 的子串,使得 v(L1,L1+3)⋅10+v(L2,L2+3)v(L_1, L_1+3)\cdot10+v(L_2,L_2+3) 除以 99 的余数为 k1=1k_1=1。实际上,取 L1=2L_1=2、L2=4L_2=4 满足所有要求:v(L1,L1+w−1)=v(2,5)=30v(L_1, L_1+w-1)=v(2,5)=30,v(L2,L2+w−1)=v(4,7)=3004v(L_2, L_2+w-1)=v(4,7)=3004。确实,30⋅10+3004=330430\cdot10+3004=3304,而 33043304 除以 99 的余数为 11。可以证明,L1=2L_1=2 是可能的最小值,且在 L1=2L_1=2 的前提下,L2=4L_2=4 是可能的最小值。

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

首页