模拟一下就行,运用两个字符串来反复模拟。

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
const ll N = 1e6 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;

int n, q;

void solve() {
    cin >> n >> q;

    string a;
    cin >> a;
    a = "*" + a;
    string b;
    while (q--) {
        int l, r;
        cin >> l >> r;
        b = "";
        for (int i = 0; i < a.size(); i++) {
            b += a[i];
            if (i >= l && i <= r)b += a[i];
        }
        a = b;
    }
    a.erase(0, 1); //删除一开始加入的*
    cout << a << '\n';
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    //cin>>t;

    while (t--) {

        solve();

    }

    return 0;
}