模拟

每次分割字符串,先用前半段完成复制操作
再组合成新字符串

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pp pop_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define UNIQUE(v) sort(all(v)); v.erase(unique(all(v)), v.end())
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define PQ priority_queue
constexpr ll inf = 1e9 + 7;

void solve() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    while (q--) {
        int l, r;
        cin >> l >> r;
        int n = s.size();
        string s1 = s.substr(0, l - 1);
        string s2 = s.substr(r, n); 
        for (int i = l - 1; i < r; i++) {
            s1.push_back(s[i]);
            s1.push_back(s[i]);
        }
        s = s1 + s2;
    }
    cout << s << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t--) solve();
    return 0;
}