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';
        }
    }
}
相关推荐
山登绝顶我为峰 3(^v^)329 分钟前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex
Two_brushes.2 小时前
【算法】宽度优先遍历BFS
算法·leetcode·哈希算法·宽度优先
十五年专注C++开发3 小时前
CMake基础:条件判断详解
c++·跨平台·cmake·自动化编译
森焱森4 小时前
水下航行器外形分类详解
c语言·单片机·算法·架构·无人机
QuantumStack5 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法
天若有情6736 小时前
01_软件卓越之道:功能性与需求满足
c++·软件工程·软件
whoarethenext6 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
写个博客6 小时前
暑假算法日记第一天
算法
绿皮的猪猪侠6 小时前
算法笔记上机训练实战指南刷题
笔记·算法·pta·上机·浙大
hie988947 小时前
MATLAB锂离子电池伪二维(P2D)模型实现
人工智能·算法·matlab