新网网站备案流程,和平网站建设,海宁做网站的公司,购物网站seo关键词定位正题
题目链接:https://www.luogu.com.cn/problem/P3850 题目大意
一个书架上有nnn本书#xff0c;进行mmm次插入操作#xff0c;然后qqq次询问一个位置上的书。 解题思路
用SplaySplaySplay进行插入操作#xff0c;然后直接查询即可 codecodecode
#includecstdio进行mmm次插入操作然后qqq次询问一个位置上的书。 解题思路
用SplaySplaySplay进行插入操作然后直接查询即可 codecodecode
#includecstdio
#includecstring
#includealgorithm
using namespace std;
const int N2e5;
int n,m,root;char s[N][15];
int tot,t[N][2],siz[N],fa[N];
void PushUp(int x)
{siz[x]siz[t[x][0]]siz[t[x][1]]1;return;}
bool Direct(int x)
{return t[fa[x]][1]x;}
void Connect(int x,int y,int son)
{t[x][son]y;fa[y]x;return;}
void Rotate(int x){int yfa[x],zfa[fa[x]];int xsDirect(x),ysDirect(y);int kt[x][xs^1];Connect(y,k,xs);Connect(x,y,xs^1);Connect(z,x,ys);PushUp(y);PushUp(x);return;
}
void Splay(int x,int f){while(fa[x]!f){int upfa[x];if(fa[up]f)Rotate(x);else if(Direct(x)Direct(up))Rotate(up),Rotate(x);else Rotate(x),Rotate(x);}return;
}
int Find(int x,int k){if(siz[t[x][0]]k)return Find(t[x][0],k);if(siz[t[x][0]]1k)return x;return Find(t[x][1],k-siz[t[x][0]]-1);
}
int main()
{scanf(%d,n);siz[1]1;for(int i1;in;i){scanf(%s,s[i1]);fa[i]i1;t[i1][0]i;PushUp(i1);}fa[n1]n2;t[n2][0]n1;PushUp(n2);roottotn2;scanf(%d,m);while(m--){scanf(%s,s[tot]);int l;scanf(%d,l);l;int xFind(root,l),yFind(root,l1);Splay(x,0);Splay(y,x);t[y][0]tot;fa[tot]y;siz[tot]1;Splay(tot,0);roottot;}scanf(%d,m);while(m--){int l;scanf(%d,l);l;int xFind(root,l),yFind(root,l2);Splay(x,0);Splay(y,x);rootx;printf(%s\n,s[t[y][0]]);}
}