这题考的不都是 string 正常的操作吗?所以难度仅仅在于 Insert 的输入?
C++ 语言里写的这些函数的复杂度应该都是 O(len) 的吧?
没看懂这题考了什么,题解和讨论区好像也没什么人讨论这个,讨论区看到了一个自称的 hack 我能通过,也不知道他 hack 了些什么。
总之就是一头雾水地过掉了。。。(本来想练练 Splay 的)
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n; string op, s, ans; char c; cin >> n;
for (int i = 1, t, p = 0; i <= n; i ++, s = "") {
cin >> op;
if (op[0] == 'M') cin >> t, p = t;
else if (op[0] == 'I') {
cin >> t;
while (t) { c = getchar(); if (c >= 32 && c <= 126) t --, s += c; }
ans.insert(p, s);
}
else if (op[0] == 'D') cin >> t, ans.erase(p, t);
else if (op[0] == 'G') { cin >> t; cout << ans.substr(p, t) << endl; }
else if (op[0] == 'P') p --;
else p ++;
}
return 0;
}