Question: give three operations
1. Insert a string at position p.
2. delete a string with a length of c from position p.
3. output the string whose length starts from position p in the v previous version to c.
Solution: You can use the Balance Tree, but not. later I heard that I could use a magic STL called roap. I learned about it and its usage is basically the same as that of string. the internal structure of the roap is implemented by the balance tree. The previous version and the current version can share some memory, and the efficiency of inserting and deleting the entire string is very high. is a persistent data structure.
// Time: 952 MS # include <iostream> # include <ext/rope> using namespace std; using namespace _ gnu_cxx; crope ro, l [50005], tmp; char str [205]; int main () {// freopen ("/home/qitaishui/code/in.txt", "r", stdin); int n, op, p, c, d, cnt, v; scanf ("% d", & n); d = 0; cnt = 1; while (n --) {scanf ("% d ", & op); if (op = 1) {scanf ("% d % s", & p, str); p-= d; ro. insert (p, str); l [cnt ++] = ro;} else if (op = 2) {scanf ("% d", & p, & c); p-= d, c-= d; ro. erase (p-1, c); l [cnt ++] = ro;} else {scanf ("% d", & v, & p, & c ); p-= d, v-= d, c-= d; tmp = l [v]. substr (p-1, c); d + = count (tmp. begin (), tmp. end (), 'C'); cout <tmp <"\ n ";}}}