Report on solving problems of the Version Controlled IDE

Source: Internet
Author: User

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 ";}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.