CF1886C.Decreasing String

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Recall that string aa is lexicographically smaller than string bb if aa is a prefix of bb (and aba \ne b ), or there exists an index ii ( 1imin(a,b)1 \le i \le \min(|a|, |b|) ) such that ai<bia_i < b_i , and for any index jj ( 1j<i1 \le j < 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 si1s_{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} ).

输入格式

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

Each test case consists of two lines. The first line contains the string s1s_1 ( 1s11061 \le |s_1| \le 10^6 ), consisting of lowercase Latin letters. The second line contains the integer pospos ( 1poss1(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=s1n = |s_1| ).

Additional constraint on the input: the sum of s1|s_1| over all test cases does not exceed 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.

输入输出样例

  • 输入#1

    3
    cab
    6
    abcd
    9
    x
    1

    输出#1

    abx
首页