splay版】的更多相关文章

Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, {A1, A2, ... An}. Then the host performs a series of…
模板,不解释 #include<bits/stdc++.h> using namespace std; const int mxn=1e5+5; int fa[mxn],ch[mxn][2],sz[mxn],cnt[mxn],val[mxn],rt,tot; namespace Splay { void push_up(int x) { sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+cnt[x]; }; void rotate(int x) { int y=fa[x],z=f…
单点插入删除以及求前缀 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,inf=; int read(){ ,f=,c=getchar(); ; c=getchar();} +(c-'); c=getchar();} return ans*f; } int n,m,root; ],size[M],fa[M],v[M],pos[M]; ]]+size[c[k][]]+…
自己yy的写法 可能有点奇怪吧 详情看代码 还是蛮短的 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,inf=0x3f3f3f3f; int read(){ ,f=,c=getchar(); ; c=getchar();} +(c-'); c=getchar();} return ans*f; } int t,root,sum,n,mn,delta,now,lea…
指针是个好东西 不过就是得判空 还有别忘传引用(其实应该都传引用) #include<cstdio> #include<algorithm> #include<iostream> using namespace std; int inf=0x7fffffff; struct node* nil; struct node { int num; int val; int size; node* ch[2]; node (int v) :val(v) { size=1; nu…
营业额统计 思路: 每次,插入一个点: 然后找前驱后继: 来,上代码: #include <cmath> #include <cstdio> #include <iostream> using namespace std; #define maxn 33000 #define INF 0x7fffffff struct TreeNodeType { ]; }; struct TreeNodeType tree[maxn]; int n,root,tot,X,ans; i…
时间限制: 3 Sec  内存限制: 128 MB提交: 49  解决: 7 题目描述 输入一个数列,你需要进行如下操作:  1. 把编号为I的数值改为K  2. 输出从小到大排序后第k个数 输入 输入文件第一行包含两个整数N.M,分别表示数列长度与操作个数.  第二行有N个整数,为初始数列中的N个整数.  接下来M行每行如果只有一个整数k,那么就是输出第k小数,否则两个整数I,K表示把第I个数的数值改为K. 输出 输出所有要求输出的数,每个数单独一行. 样例输入 5 3 5 3 2 1 1 4…
链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p和s(1≤pi≤n,1≤si≤n-pi+1),表示把序列中从p开始的s个数移到最前面,例如序列[1,2,3,4,5]在p=2,s=3时变成序列[2,3,4,1,5],输出最后的序列. 分析: 对于每个操作,直接把序列拆成三个部分,再重新拼接一下就行.可以用Splay或rope来快速完成这个操作. 代…
浅谈\(splay\):https://www.cnblogs.com/AKMer/p/9979592.html 浅谈\(fhq\)_\(treap\):https://www.cnblogs.com/AKMer/p/9981274.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2028 此题的线段树写法:https://www.cnblogs.com/AKMer/p/9948789.html 我如果要插入一个新的区间\(…
题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除x数(若有多个相同的数,因只删除一个) 查询x数的排名(若有多个相同的数,因输出最小的排名) 查询排名为x的数 求x的前驱(前驱定义为小于x,且最大的数) 求x的后继(后继定义为大于x,且最小的数) 输入输出格式 输入格式: 第一行为n,表示操作的个数,下面n行每行有两个数opt和x,opt表示操作的序号(1<=opt<=6) 输出格式: 对于操作3,4,5,6每行输出一个数,表示对应答案 输…