1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include<algorithm> #include<iostream> #include<ext/rope> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; using namespace __gnu_cxx; rope<char>R,revR; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } void Get_String(int n,char* a) { for(int i=0; i<n; i++) { a[i]='\0'; while(a[i]<32||a[i]>126)a[i]=getchar(); } a[n]='\0'; } char a[1<<20],b[1<<20]; int t,pos=0; int main() { t=Get_Int(); while(t--) { char opt='\0'; while(!isalpha(opt=getchar())); while(isalpha(getchar())); if(opt=='P')pos--; else if(opt=='N')pos++; else if(opt=='G')printf("%c\n",R[pos]); else if(opt=='M')pos=Get_Int(); else if(opt=='I') { int len=Get_Int(); Get_String(len,a); memcpy(b,a,sizeof(a)); reverse(b,b+len); R.insert(pos,a); revR.insert(revR.length()-pos,b); } else if(opt=='D') { int len=Get_Int(); R.erase(pos,len); revR.erase(revR.length()-pos-len,len); } else if(opt=='R') { int len=Get_Int(); rope<char>tmp1,tmp2; int L=revR.length(); tmp1=R.substr(pos,len); tmp2=revR.substr(L-pos-len,len); R=R.substr(0,pos)+tmp2+R.substr(pos+len,L-pos-len); revR=revR.substr(0,L-pos-len)+tmp1+revR.substr(L-pos,pos); } } return 0; }
|