C. Mark and His Unfinished Essay - 思维

分析:

直接模拟操作会mle,可以每次复制记录对应源字符串的下标,可以记录每次字符串增加的长度的左右端点下标,可以发现左端点与读入的l是对应的,因此就可以向前移到l的位置,这样层层递归,就能找到在原字符串的相对位置,能够向前移动的前提是查询的下标要在每次记录的区间以内。

代码:

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T --) {
        int n, c, q;
        cin >> n >> c >> q;
        string s;
        cin >> s;
        s = " " + s;
        vector<ll> left(c + 1), right(c + 1), d(c + 1);
        right[0] = n;
        left[0] = 1;
        for(int i = 1; i <= c; i ++) {
            ll l, r;
            cin >> l >> r;
            left[i] = right[i - 1] + 1;
            right[i] = left[i] + r - l;
            d[i] = left[i] - l;
        }
      //  for(int i = 1; i <= c; i ++) cout << left[i] << ' ' << right[i] << ' ' << d[i] << endl;
        while(q --) {
            ll x;
            cin >> x;
            for(int i = c; i >= 1; i --) {
                if(left[i] <= x&&x <= right[i]) {
                  //  cout << left[i] << ' ' << right[i] << endl;
                  //  cout << d[i] << endl;
                    x -= d[i];
                }
            }
           // cout << x << endl;
            cout << s[x] << '\n';
        }
    }
}
相关推荐
qq_5139704411 分钟前
力扣 hot100 Day37
算法·leetcode
不見星空31 分钟前
leetcode 每日一题 1865. 找出和为指定值的下标对
算法·leetcode
我爱Jack41 分钟前
时间与空间复杂度详解:算法效率的度量衡
java·开发语言·算法
米饭「」43 分钟前
C++AVL树
java·开发语言·c++
心愿许得无限大1 小时前
Qt 常用界面组件
开发语言·c++·qt
GiraKoo2 小时前
【GiraKoo】C++17的新特性
c++
Rockson2 小时前
C++如何查询实时贵金属行情
c++·api
shenyan~2 小时前
关于 c、c#、c++ 三者区别
开发语言·c++
DoraBigHead2 小时前
小哆啦解题记——映射的背叛
算法
mit6.8242 小时前
[vroom] docs | 输入与问题定义 | 任务与运输工具 | json
c++·自动驾驶