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';
        }
    }
}
相关推荐
三毛的二哥4 小时前
BEV:典型BEV算法总结
人工智能·算法·计算机视觉·3d
南宫萧幕5 小时前
自控PID+MATLAB仿真+混动P0/P1/P2/P3/P4构型
算法·机器学习·matlab·simulink·控制·pid
浪浪小洋6 小时前
c++ qt课设定制
开发语言·c++
charlie1145141916 小时前
嵌入式C++工程实践第16篇:第四次重构 —— LED模板,从通用GPIO到专用抽象
c语言·开发语言·c++·驱动开发·嵌入式硬件·重构
handler016 小时前
Linux: 基本指令知识点(2)
linux·服务器·c语言·c++·笔记·学习
故事和你916 小时前
洛谷-数据结构1-4-图的基本应用1
开发语言·数据结构·算法·深度优先·动态规划·图论
我叫黑大帅6 小时前
为什么map查找时间复杂度是O(1)?
后端·算法·面试
炽烈小老头7 小时前
【每天学习一点算法 2026/04/20】除自身以外数组的乘积
学习·算法
skilllite作者7 小时前
AI agent 的 Assistant Auto LLM Routing 规划的思考
网络·人工智能·算法·rust·openclaw·agentskills
香蕉鼠片8 小时前
MFC是什么
c++·mfc