Stretching: Rotates a specific node in the treap to the root
//extend the sequence from the left to the K elements to the root, note that the node key value is the original sequence ID savedvoidSplay (node* &o,intk) {ints = o->ch[0] = = NULL?0: o->ch[0]->s; intD = k <= s?0: (k = = S+1? -1:1); if(d = =1) K-= S+1; if(d! =-1) {splay (o-Ch[d], k); Rotate (o, D^1); }}//Merge operation: S1 the sequence, S2, S1 on the leftnode* Merge (node* left, node*Right ) {splay (left, left-R); Left->ch[1] =Right ; Left-maintain (); returnLeft ;}//split operation: divides the sequence s into two consecutive sub-sequences, the left subsequence contains k elements, and the right subsequence contains the remaining elementsvoidSplit (node* O,intK, node* &left, node* &Right ) {splay (o, k); Left=o; Right= o->ch[1]; o->ch[1] =NULL; Left-maintain ();}
Template--stretching tree splay for fast splitting and merging sequences