[题解] treap模板题,直接用Treap维护前驱.后继,每次找到更接近当前val的加上就好了. #include<cstdio> #include<algorithm> #define ls (a[u].l) #define rs (a[u].r) #define LL long long using namespace std; ; int n,k,x,y,z,v,tot,root; struct treap{int l,r,v,rnd,size;}a[maxn]; LL s…
题目链接 //模板吧 #include<cstdio> #include<cctype> #include<algorithm> using namespace std; const int N=40000,INF=1e8; int n,size,root,sz[N],cnt[N],t[N],son[N][2],fa[N]; inline int read() { int now=0,f=1;register char c=getchar(); for(;!isdigi…