CF1705C.Mark and His Unfinished Essay

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One night, Mark realized that there is an essay due tomorrow. He hasn't written anything yet, so Mark decided to randomly copy-paste substrings from the prompt to make the essay.

More formally, the prompt is a string ss of initial length nn. Mark will perform the copy-pasting operation cc times. Each operation is described by two integers ll and rr, which means that Mark will append letters slsl+1…srs_l s_{l+1} \ldots s_r to the end of string ss. Note that the length of ss increases after this operation.

Of course, Mark needs to be able to see what has been written. After copying, Mark will ask qq queries: given an integer kk, determine the kk-th letter of the final string ss.

一天夜里,马克意识到明天有一篇论文要交。他至今一个字都没写,于是决定从题目提示中随机复制粘贴子串来完成这篇论文。

更准确地说,题目提示是一个初始长度为 nn 的字符串 ss。马克将执行 cc 次复制粘贴操作。每次操作由两个整数 ll 和 rr 描述,表示马克将把子串 slsl+1…srs_l s_{l+1} \ldots s_r 追加到字符串 ss 的末尾。注意:该操作会使 ss 的长度增加。

当然,马克需要能查看已写入的内容。在所有复制操作完成后,马克会提出 qq 个查询:对每个给定的整数 kk,确定最终字符串 ss 中第 kk 个字符。

输入格式

The first line contains a single integer tt (1≤t≤10001\leq t\leq 1000) — the number of test cases.

The first line of each test case contains three integers nn, cc, and qq (1≤n≤2⋅1051\leq n\leq 2\cdot 10^5, 1≤c≤401\leq c\leq 40, and 1≤q≤1041\leq q\leq 10^4) — the length of the initial string ss, the number of copy-pasting operations, and the number of queries, respectively.

The second line of each test case contains a single string ss of length nn. It is guaranteed that ss only contains lowercase English letters.

The following cc lines describe the copy-pasting operation. Each line contains two integers ll and rr (1≤l≤r≤10181\leq l\leq r\leq 10^{18}). It is also guaranteed that rr does not exceed the current length of ss.

The last qq lines of each test case describe the queries. Each line contains a single integer kk (1≤k≤10181\leq k\leq 10^{18}). It is also guaranteed that kk does not exceed the final length of ss.

It is guaranteed that the sum of nn and qq across all test cases does not exceed 2⋅1052\cdot 10^5 and 10410^4, respectively.

第一行包含一个整数 tt(1≤t≤10001\leq t\leq 1000)—— 表示测试用例的数量。

每个测试用例的第一行包含三个整数 nn、cc 和 qq(1≤n≤2⋅1051\leq n\leq 2\cdot 10^5,1≤c≤401\leq c\leq 40,1≤q≤1041\leq q\leq 10^4)—— 分别表示初始字符串 ss 的长度、复制粘贴操作的次数以及查询的次数。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss。保证 ss 仅由小写英文字母组成。

接下来的 cc 行描述复制粘贴操作。每行包含两个整数 ll 和 rr(1≤l≤r≤10181\leq l\leq r\leq 10^{18})。同时保证 rr 不超过当前字符串 ss 的长度。

每个测试用例的最后 qq 行描述查询。每行包含一个整数 kk(1≤k≤10181\leq k\leq 10^{18})。同时保证 kk 不超过最终字符串 ss 的长度。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5,且 qq 的总和不超过 10410^4。

输出格式

For each query, print the kk-th letter of the final string ss.

对于每个查询,输出最终字符串 ss 的第 kk 个字母。

输入输出样例

  • 输入#1

    2
    4 3 3
    mark
    1 4
    5 7
    3 8
    1
    10
    12
    7 3 3
    creamii
    2 3
    3 4
    2 9
    9
    11
    12

    输出#1

    m
    a
    r
    e
    a
    r

说明/提示

In the first test case, the copy-paste process is as follows.

  • The first step is pasting string mark\texttt{mark} at the end, yielding the string markmark\texttt{mark}\color{red}{\texttt{mark}}.
  • The second step is pasting string mar\texttt{mar} at the end, yielding the string markmarkmar\texttt{markmark}\color{red}{\texttt{mar}}.
  • The third step is pasting string rkmark\texttt{rkmark} at the end, yielding the string markmarkmarrkmark\texttt{markmarkmar}\color{red}{\texttt{rkmark}}.

In the second test case, the copy-paste process is as follows.

  • The first step is pasting string re\texttt{re} at the end, yielding the string creamiire\texttt{creamii}\color{red}{\texttt{re}}.
  • The second step is pasting string ea\texttt{ea} at the end, yielding the string creamiireea\texttt{creamiire}\color{red}{\texttt{ea}}.
  • The third step is pasting string reamiire\texttt{reamiire} at the end, yielding the string creamiireeareamiire\texttt{creamiireea}\color{red}{\texttt{reamiire}}.

在第一个测试用例中,复制-粘贴过程如下:

  • 第一步:在末尾粘贴字符串 mark\texttt{mark},得到字符串 markmark\texttt{mark}\color{red}{\texttt{mark}}。
  • 第二步:在末尾粘贴字符串 mar\texttt{mar},得到字符串 markmarkmar\texttt{markmark}\color{red}{\texttt{mar}}。
  • 第三步:在末尾粘贴字符串 rkmark\texttt{rkmark},得到字符串 markmarkmarrkmark\texttt{markmarkmar}\color{red}{\texttt{rkmark}}。

在第二个测试用例中,复制-粘贴过程如下:

  • 第一步:在末尾粘贴字符串 re\texttt{re},得到字符串 creamiire\texttt{creamii}\color{red}{\texttt{re}}。
  • 第二步:在末尾粘贴字符串 ea\texttt{ea},得到字符串 creamiireea\texttt{creamiire}\color{red}{\texttt{ea}}。
  • 第三步:在末尾粘贴字符串 reamiire\texttt{reamiire},得到字符串 creamiireeareamiire\texttt{creamiireea}\color{red}{\texttt{reamiire}}。

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

首页