codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1705C.md (3084B)


      1 Source: https://codeforces.com/problemset/problem/1705/C
      2 
      3 C. Mark and His Unfinished Essay
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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$.
     26 
     27 Input
     28 
     29 The first line contains a single integer $t$ ($1\leq t\leq 1000$) — the number of test cases.
     30 
     31 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.
     32 
     33 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.
     34 
     35 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$.
     36 
     37 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$.
     38 
     39 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.
     40 
     41 Output
     42 
     43 For each query, print the $k$-th letter of the final string $s$.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 2
     51 
     52 4 3 3
     53 
     54 mark
     55 
     56 1 4
     57 
     58 5 7
     59 
     60 3 8
     61 
     62 1
     63 
     64 10
     65 
     66 12
     67 
     68 7 3 3
     69 
     70 creamii
     71 
     72 2 3
     73 
     74 3 4
     75 
     76 2 9
     77 
     78 9
     79 
     80 11
     81 
     82 12
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 m
     89 a
     90 r
     91 e
     92 a
     93 r
     94 ```
     95 
     96 Note
     97 
     98 In the first test case, the copy-paste process is as follows.
     99 
    100 * The first step is pasting string $\texttt{mark}$ at the end, yielding the string $\texttt{mark}\color{red}{\texttt{mark}}$.
    101 * The second step is pasting string $\texttt{mar}$ at the end, yielding the string $\texttt{markmark}\color{red}{\texttt{mar}}$.
    102 * The third step is pasting string $\texttt{rkmark}$ at the end, yielding the string $\texttt{markmarkmar}\color{red}{\texttt{rkmark}}$.
    103 
    104 In the second test case, the copy-paste process is as follows.
    105 
    106 * The first step is pasting string $\texttt{re}$ at the end, yielding the string $\texttt{creamii}\color{red}{\texttt{re}}$.
    107 * The second step is pasting string $\texttt{ea}$ at the end, yielding the string $\texttt{creamiire}\color{red}{\texttt{ea}}$.
    108 * The third step is pasting string $\texttt{reamiire}$ at the end, yielding the string $\texttt{creamiireea}\color{red}{\texttt{reamiire}}$.