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';
        }
    }
}
相关推荐
代码中介商2 小时前
C++ STL 容器完全指南(二):vector 深入与 stringstream 实战
开发语言·c++
YUDAMENGNIUBI3 小时前
day20_逻辑回归
算法·机器学习·逻辑回归
澈2077 小时前
C++并查集:高效解决连通性问题
java·c++·算法
郝学胜-神的一滴8 小时前
Qt 入门 01-01:从零基础到商业级客户端实战
开发语言·c++·qt·程序人生·软件构建
宏笋8 小时前
C++ thread的detach()方法详解
c++
旖-旎8 小时前
深搜练习(单词搜索)(12)
c++·算法·深度优先·力扣
企客宝CRM9 小时前
2026年中小企业CRM选型指南:企客宝CRM处于什么位置?
android·算法·企业微信·rxjava·crm
橙淮9 小时前
二叉树核心概念与Java实现详解
数据结构·算法
大卡片10 小时前
C++的基础知识点
开发语言·c++
米罗篮10 小时前
DSU并查集 & 拓展欧几里得-逆元
c++·经验分享·笔记·算法·青少年编程