CF1886C.Decreasing String

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recall that string aa is lexicographically smaller than string bb if aa is a prefix of bb (and a≠ba \ne b), or there exists an index ii (1≤i≤min⁡(∣a∣,∣b∣)1 \le i \le \min(|a|, |b|)) such that ai<bia_i \lt b_i, and for any index jj (1≤j<i1 \le j \lt i) aj=bja_j = b_j.

Consider a sequence of strings s1,s2,…,sns_1, s_2, \dots, s_n, each consisting of lowercase Latin letters. String s1s_1 is given explicitly, and all other strings are generated according to the following rule: to obtain the string sis_i, a character is removed from string si−1s_{i-1} in such a way that string sis_i is lexicographically minimal.

For example, if s1=dacbs_1 = \mathrm{dacb}, then string s2=acbs_2 = \mathrm{acb}, string s3=abs_3 = \mathrm{ab}, string s4=as_4 = \mathrm{a}.

After that, we obtain the string S=s1+s2+⋯+snS = s_1 + s_2 + \dots + s_n (SS is the concatenation of all strings s1,s2,…,sns_1, s_2, \dots, s_n).

You need to output the character in position pospos of the string SS (i. e. the character SposS_{pos}).

回忆一下,若字符串 aa 是字符串 bb 的前缀(且 a≠ba \ne b),或存在某个下标 ii(满足 1≤i≤min⁡(∣a∣,∣b∣)1 \le i \le \min(|a|, |b|)),使得 ai<bia_i \lt b_i,且对任意下标 jj(满足 1≤j<i1 \le j \lt i)都有 aj=bja_j = b_j,则称字符串 aa 在字典序上小于字符串 bb。

考虑一个由小写拉丁字母组成的字符串序列 s1,s2,…,sns_1, s_2, \dots, s_n。其中字符串 s1s_1 被显式给出,其余所有字符串均按如下规则生成:为得到字符串 sis_i,需从字符串 si−1s_{i-1} 中删去一个字符,使得 sis_i 的字典序最小。

例如,若 s1=dacbs_1 = \mathrm{dacb},则 s2=acbs_2 = \mathrm{acb},s3=abs_3 = \mathrm{ab},s4=as_4 = \mathrm{a}。

随后,我们构造字符串 S=s1+s2+⋯+snS = s_1 + s_2 + \dots + s_n(即 SS 是所有字符串 s1,s2,…,sns_1, s_2, \dots, s_n 的拼接)。

你需要输出字符串 SS 中位置为 pospos 的字符(即字符 SposS_{pos})。

输入格式

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

Each test case consists of two lines. The first line contains the string s1s_1 (1≤∣s1∣≤1061 \le |s_1| \le 10^6), consisting of lowercase Latin letters. The second line contains the integer pospos (1≤pos≤∣s1∣⋅(∣s1∣+1)21 \le pos \le \frac{|s_1| \cdot (|s_1| +1)}{2}). You may assume that nn is equal to the length of the given string (n=∣s1∣n = |s_1|).

Additional constraint on the input: the sum of ∣s1∣|s_1| over all test cases does not exceed 10610^6.

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

每个测试用例由两行组成。第一行包含字符串 s1s_1(1≤∣s1∣≤1061 \le |s_1| \le 10^6),该字符串仅由小写拉丁字母组成;第二行包含整数 pospos(1≤pos≤∣s1∣⋅(∣s1∣+1)21 \le pos \le \frac{|s_1| \cdot (|s_1| +1)}{2})。你可以假设 nn 等于给定字符串的长度(即 n=∣s1∣n = |s_1|)。

输入的额外约束:所有测试用例中 ∣s1∣|s_1| 的总和不超过 10610^6。

输出格式

For each test case, print the answer — the character that is at position pospos in string SS. Note that the answers between different test cases are not separated by spaces or line breaks.

对于每个测试用例,输出答案——即字符串 SS 中位置为 pospos 的字符。注意:不同测试用例的答案之间不以空格或换行符分隔。

输入输出样例

  • 输入#1

    3
    cab
    6
    abcd
    9
    x
    1

    输出#1

    abx

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

首页