1 #include<cstdio> 2 #include<iostream> 3 #include<ext/rope> 4 using namespace std; 5 using namespace __gnu_cxx; 6 crope list; 7 int n,now; 8 char ch[10],ch1[3000005]; 9 int main() 10 { 11 scanf("%d",&n); 12 for(int i=1;i<=n;i++) 13 { 14 int a1; 15 scanf("%s",ch); 16 if(ch[0]!='P'&&ch[0]!='N') 17 scanf("%d",&a1); 18 if(ch[0]=='M') 19 now=a1; 20 if(ch[0]=='I') 21 { 22 for(int i=0;i<a1;i++) 23 { 24 ch1[i]=getchar(); 25 for(;ch1[i]=='\n';ch1[i]=getchar()); 26 } 27 ch1[a1]=0; 28 list.insert(now,ch1); 29 } 30 if(ch[0]=='D') 31 list.erase(now,a1); 32 if(ch[0]=='G') 33 { 34 list.copy(now,a1,ch1); 35 ch1[a1]=0; 36 printf("%s\n",ch1); 37 } 38 if(ch[0]=='P') 39 now--; 40 if(ch[0]=='N') 41 now++; 42 } 43 return 0; 44 }
本应是个平衡树,偷懒用了list。