A15201 | Mark and His Unfinished Essay
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $s$ of initial length $n$ . Mark will perform the copy-pasting operation $c$ times. Each operation is described by two integers $l$ and $r$ , which means that Mark will append letters $s_l s_{l+1} \ldots s_r$ to the end of string $s$ . Note that the length of $s$ increases after this operation.
Of course, Mark needs to be able to see what has been written. After copying, Mark will ask $q$ queries: given an integer $k$ , determine the $k$ -th letter of the final string $s$ .
More formally, the prompt is a string $s$ of initial length $n$ . Mark will perform the copy-pasting operation $c$ times. Each operation is described by two integers $l$ and $r$ , which means that Mark will append letters $s_l s_{l+1} \ldots s_r$ to the end of string $s$ . Note that the length of $s$ increases after this operation.
Of course, Mark needs to be able to see what has been written. After copying, Mark will ask $q$ queries: given an integer $k$ , determine the $k$ -th letter of the final string $s$ .
输入格式
The first line contains a single integer $t$ ( $1\leq t\leq 1000$ ) — the number of test cases.
The first line of each test case contains three integers $n$ , $c$ , and $q$ ( $1\leq n\leq 2\cdot 10^5$ , $1\leq c\leq 40$ , and $1\leq q\leq 10^4$ ) — the length of the initial string $s$ , the number of copy-pasting operations, and the number of queries, respectively.
The second line of each test case contains a single string $s$ of length $n$ . It is guaranteed that $s$ only contains lowercase English letters.
The following $c$ lines describe the copy-pasting operation. Each line contains two integers $l$ and $r$ ( $1\leq l\leq r\leq 10^{18}$ ). It is also guaranteed that $r$ does not exceed the current length of $s$ .
The last $q$ lines of each test case describe the queries. Each line contains a single integer $k$ ( $1\leq k\leq 10^{18}$ ). It is also guaranteed that $k$ does not exceed the final length of $s$ .
It is guaranteed that the sum of $n$ and $q$ across all test cases does not exceed $2\cdot 10^5$ and $10^4$ , respectively.
The first line of each test case contains three integers $n$ , $c$ , and $q$ ( $1\leq n\leq 2\cdot 10^5$ , $1\leq c\leq 40$ , and $1\leq q\leq 10^4$ ) — the length of the initial string $s$ , the number of copy-pasting operations, and the number of queries, respectively.
The second line of each test case contains a single string $s$ of length $n$ . It is guaranteed that $s$ only contains lowercase English letters.
The following $c$ lines describe the copy-pasting operation. Each line contains two integers $l$ and $r$ ( $1\leq l\leq r\leq 10^{18}$ ). It is also guaranteed that $r$ does not exceed the current length of $s$ .
The last $q$ lines of each test case describe the queries. Each line contains a single integer $k$ ( $1\leq k\leq 10^{18}$ ). It is also guaranteed that $k$ does not exceed the final length of $s$ .
It is guaranteed that the sum of $n$ and $q$ across all test cases does not exceed $2\cdot 10^5$ and $10^4$ , respectively.
输出格式
For each query, print the $k$ -th letter of the final string $s$ .
输入输出样例
输入 #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 $\texttt{mark}$ at the end, yielding the string $\texttt{mark}\color{red}{\texttt{mark}}$ .
- The second step is pasting string $\texttt{mar}$ at the end, yielding the string $\texttt{markmark}\color{red}{\texttt{mar}}$ .
- The third step is pasting string $\texttt{rkmark}$ at the end, yielding the string $\texttt{markmarkmar}\color{red}{\texttt{rkmark}}$ .
In the second test case, the copy-paste process is as follows.
- The first step is pasting string $\texttt{re}$ at the end, yielding the string $\texttt{creamii}\color{red}{\texttt{re}}$ .
- The second step is pasting string $\texttt{ea}$ at the end, yielding the string $\texttt{creamiire}\color{red}{\texttt{ea}}$ .
- The third step is pasting string $\texttt{reamiire}$ at the end, yielding the string $\texttt{creamiireea}\color{red}{\texttt{reamiire}}$ .
- The first step is pasting string $\texttt{mark}$ at the end, yielding the string $\texttt{mark}\color{red}{\texttt{mark}}$ .
- The second step is pasting string $\texttt{mar}$ at the end, yielding the string $\texttt{markmark}\color{red}{\texttt{mar}}$ .
- The third step is pasting string $\texttt{rkmark}$ at the end, yielding the string $\texttt{markmarkmar}\color{red}{\texttt{rkmark}}$ .
In the second test case, the copy-paste process is as follows.
- The first step is pasting string $\texttt{re}$ at the end, yielding the string $\texttt{creamii}\color{red}{\texttt{re}}$ .
- The second step is pasting string $\texttt{ea}$ at the end, yielding the string $\texttt{creamiire}\color{red}{\texttt{ea}}$ .
- The third step is pasting string $\texttt{reamiire}$ at the end, yielding the string $\texttt{creamiireea}\color{red}{\texttt{reamiire}}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted