/**
* Author: someone on Codeforces
* Date: 2017-03-14
* Source: folklore
* Description: A short self-balancing tree. It acts as a
* sequential container with log-time splits/joins, and
* is easy to augment with additional data.
* Time: $O(\log N)$
* Status: stress-tested
*/#pragma once
structNode{Node*l=0,*r=0;intval,y,c=1;Node(intval):val(val),y(rand()){}voidrecalc();};intcnt(Node*n){returnn?n->c:0;}voidNode::recalc(){c=cnt(l)+cnt(r)+1;}template<classF>voideach(Node*n,Ff){if(n){each(n->l,f);f(n->val);each(n->r,f);}}pair<Node*,Node*>split(Node*n,intk){if(!n)return{};if(cnt(n->l)>=k){// "n->val >= k" for lower_bound(k)auto[L,R]=split(n->l,k);n->l=R;n->recalc();return{L,n};}else{auto[L,R]=split(n->r,k-cnt(n->l)-1);// and just "k"n->r=L;n->recalc();return{n,R};}}Node*merge(Node*l,Node*r){if(!l)returnr;if(!r)returnl;if(l->y>r->y){l->r=merge(l->r,r);returnl->recalc(),l;}else{r->l=merge(l,r->l);returnr->recalc(),r;}}Node*ins(Node*t,Node*n,intpos){auto[l,r]=split(t,pos);returnmerge(merge(l,n),r);}// Example application: move the range [l, r) to index kvoidmove(Node*&t,intl,intr,intk){Node*a,*b,*c;tie(a,b)=split(t,l);tie(b,c)=split(b,r-l);if(k<=l)t=merge(ins(a,b,k),c);elset=merge(a,ins(c,b,k-r));}
Traceback(mostrecentcalllast):File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/documentation/build.py",line71,in_render_source_code_statbundled_code=language.bundle(stat.path,basedir=basedir,options={'include_paths':[basedir]}).decode()~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/languages/cplusplus.py",line187,inbundlebundler.update(path)~~~~~~~~~~~~~~^^^^^^File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py",line312,inupdateraiseBundleErrorAt(path,i+1,"#pragma once found in a non-first line")onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt:src/data-structures/Treap.h:line11:#pragmaoncefoundinanon-firstline