题目也是中文的就不说题意了。新开一个变量pos记录光标在第pos个节点,因为头尾同样要虚拟一个头结点和尾结点,所以光标也就是指向当前序列的第pos-1个字符。move,prev,next直接修改pos的值就行,剩下的就都是伸展树的基本操作了。insert操作就把pos伸展到根,pos+1伸展到根的下边,向pos+1的左孩子循环添加节点就行,添加完记得自底而上pushup回来。rotate就把pos伸展到根,pos+c+1伸展到根的下边,旋转pos+c+1的左子树,delete也同样把目标区间旋转到根的右孩子的左孩子,删掉即可,get就把pos伸展到根,输出根的值。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn=2000000+50000;
int pre[maxn],ch[maxn][2];
int flip[maxn];
int size[maxn];
char key[maxn];
int root,n,tot;
int m,p,q,r,t,tt;
struct splaytree
{
int pos;
void pushup(int r)
{
size[r]=1+size[ch[r][0]]+size[ch[r][1]];
}
void go_f(int r)
{
flip[r]^=1;