http://www.lydsy.com/JudgeOnline/problem.php?id=1507
rope真是个好东西
不用手写平衡树或块状链表了
#include<cstdio> #include<cstring> #include<ext/rope> #define FOR(i,s,t) for(register int i=s;i<=t;++i) using namespace __gnu_cxx; const int size=2333333; char S[size]; char Q[23]; crope list; int t,x,now; int main(){ scanf("%d",&t); while(t--){ scanf("%s",Q); switch(Q[0]){ case 'I':{ scanf("%d",&x); for(register int i=0;i!=x;++i){ S[i]=getchar(); while(S[i]==' ')S[i]=getchar(); } S[x]=0; list.insert(now,S); break; } case 'M':{scanf("%d",&now);break;} case 'D':{scanf("%d",&x);list.erase(now,x);break;} case 'G':{scanf("%d",&x);list.copy(now,x,S);S[x]=0;puts(S);break;} case 'P':{--now;break;} case 'N':{++now;break;} } } return 0; }