CF. Mark and His Unfinished Essay
对于巨长的字符串复制后进行查询可以逐层向上推导前一次复制所在的位置,复制前所在的位置等于复制的字符串在当前字符串的左端点减去复制的字符串在没有复制之前的字符串左端点的位置
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
const int N = 2e5 + 10;
typedef long long LL;
LL l[N], r[N], lc[N], rc[N];
int main()
{
int t;
cin >> t;
while(t --)
{
int n, k , c;
cin >> n >> k >> c;
string s;
cin >> s;
LL len = s.size();
for(int i = 1; i <= k; i ++)
{
cin >> l[i] >> r[i];
LL tp = r[i] - l[i] + 1;
lc[i] = len + 1, rc[i] = lc[i] + tp - 1;
len += tp;
}
while(c --)
{
LL q;
cin >> q;
for(int i = k; i >= 1; i --)
{
if(q >= lc[i] && q <= rc[i])
{
q -= lc[i] - l[i];
}
}
cout << s[q - 1]<< endl;
}
}
}