```cpp
#include<iostream>
#include<cstdio>
using namespace std;
#define N 2000000
int pos;
bool mark;
char in[N];
void read(int len) {
int i=0;
while(i<len) {
scanf("%c",&in[i+1]);
if(in[i+1]!='\n') i++;
}
}
struct Splay_tree {
int rot,num;
char key[N];
int siz[N],fa[N],ch[N][2];
void clear() {
ch[0][0]=ch[0][1]=fa[0]=siz[0]=mark=0;
}
void New(int &x,char c,int fat) {
x=++num;
ch[x][0]=ch[x][1]=0;
fa[x]=fat;
key[x]=c;
siz[x]=1;
}
void update(int x) {
siz[x]=siz[ch[x][0]]+siz[ch[x][1]]+1;
}
void build(int &x,int l,int r,int fat) {
if(l>r) return;
int mid=(l+r)>>1;
New(x,in[mid],fat);
build(ch[x][0],l,mid-1,x);
build(ch[x][1],mid+1,r,x);
update(x);
}
void rotate(int x) {
int y=fa[x],z=fa[y];
bool d=(ch[y][1]==x);
if(z) ch[z][ch[z][1]==y]=x;
fa[x]=z;
ch[y][d]=ch[x][d^1];
fa[ch[x][d^1]]=y;
ch[x][d^1]=y;
fa[y]=x;
update(x),update(y);
}
void splay(int x,int k) {
while(fa[x]!=k) {
int y=fa[x],z=fa[y];
if(z!=k) {
if((ch[y][1]==x)^(ch[z][1]==y)) rotate(x);
else rotate(y);
}
rotate(x);
}
if(!k) rot=x;
update(x);
}
void rotateto(int k,int goal) {
int x=rot;
while(siz[ch[x][0]]+1!=k) {
if(siz[ch[x][0]]+1<k) k-=siz[ch[x][0]]+1,x=ch[x][1];
else x=ch[x][0];
}
splay(x,goal);
}
void insert(int pos,int len) {
rotateto(pos+1,0);
rotateto(pos+2,rot);
build(ch[ch[rot][1]][0],1,len,ch[rot][1]);
update(ch[rot][1]),update(rot);
}
void del(int pos,int len) {
rotateto(pos+1,0);
rotateto(pos+len+2,rot);
ch[ch[rot][1]][0]=0;
update(ch[rot][1]),update(rot);
}
void vis(int x) {
if(ch[x][0]) vis(ch[x][0]);
if(key[x]!='\n') printf("%c",key[x]);
if(ch[x][1]) vis(ch[x][1]);
}
void get(int pos,int len) {
rotateto(pos+1,0);
rotateto(pos+2+len,rot);
if(mark) printf("\n");
else mark=1;
vis(ch[ch[rot][1]][0]);
}
}T;
int main()
{
int Q;
scanf("%d",&Q);
T.clear();
T.New(T.rot,0,'\n'),T.New(T.ch[T.rot][1],T.rot,'\n');
char s[15]={0};
int len=0;
while(Q--) {
scanf("%s",s);
if(s[0]=='M') scanf("%d",&pos);
else if(s[0]=='I') {
scanf("%d",&len);
read(len);
T.insert(pos,len);
}
else if(s[0]=='D') scanf("%d",&len),T.del(pos,len);
else if(s[0]=='G') scanf("%d",&len),T.get(pos,len);
else if(s[0]=='P') pos--;
else if(s[0]=='N') pos++;
}
return 0;
}
```
by 雨季 @ 2018-01-29 08:22:23
是不是忽视了\n但没有忽视\r的问题?
题解的第一篇里有讲到输入有\r也要当换行忽略。
@[雨季](/space/show?uid=36728)
by Just_do_it @ 2018-02-21 16:02:43
@[雨季](/user/36728)
确实, 同样的其他oj ac luogu一个点也没过去
在luogu判了'\r'就ac了
by bigj @ 2023-04-12 09:47:58