POJ 1442 Treap模板】的更多相关文章

// by SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int cnt=0,jy,a[30500],n,m,root=-1; struct node{ int left,right,count_left,count_right,key,priority; }treap[30500]; void zig(int &x){ int y…
裸treap. 只需增加一个size记录其儿子个数便可找到第k大数. #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include <vector>…
题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> using namespace std; struct Node { Node *ch[2]; int r; int v; int s; Node(){} Node(int v): v(v)…
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 12171  Solved: 4352 Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额.分析营业情况是一项相当复杂的工作.由于节假日,大减价或者是其他情况的时候,营业额会出现一定的波动,当然一定的波…
解题关键:treap模板保存. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #include<ctime> #define inf 2e9 using namespace std; ; struct tree{ int l,r;//左右儿子节点编号 in…
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #define ll long lo…
题目地址:POJ 1442 这题是用了两个优先队列,当中一个是较大优先.还有一个是较小优先. 让较大优先的队列保持k个.每次输出较大优先队列的队头. 每次取出一个数之后,都要先进行推断,假设这个数比較大优先的队列的队头要小,就让它增加这个队列.队列头移到较小优先的队列中.然后当较大优先的数不足k个的时候,就让较小优先的队列的队头移到较大优先的队头中. 代码例如以下. #include <iostream> #include <cstdio> #include <string&…
题目链接:http://poj.org/problem?id=1442 思路分析: <1>维护一个最小堆与最大堆,最大堆中存储最小的K个数,其余存储在最小堆中; <2>使用Treap构造名次树,查询第K大数即可; 代码如下(堆的用法): #include<iostream> #include<queue> using namespace std; struct cmp1 { bool operator() ( const int a, const int b…
Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provid…
Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank i…
最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获很多,这一天做的题都是有一定普遍性的. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include…
这回要求的是第k小的元素, 参考了ljl大神的模板,orz //insert 插入 //remove 删除 //_find 查找 //kth 返回root为根的树中第k小的元素 //treap插入.删除.查询时间复杂度均为O(logn) #include <iostream> #include <cstring> #include <cstdlib> #include <ctime> #include <cstdio> using namespa…
题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人的 代码,很巧妙的设计 #include<stdio.h> #include<queue> using namespace std; ]; int main() { int n,i,m,j,u; priority_queue< int,vector<int>,less…
原理可以看hihocoder上面的讲解,很清楚,不多说了. 模板抄lrj训练指南上面的. /** Treap 实现 名次树 功能: 1.找到排名为k的元素 2.值为x的元素的名次 初始化:Node* root = NULL; */ #include <cstdlib> #include <cstdio> #include <cstring> #include <vector> using namespace std; struct Node { Node *…
题目: http://poj.org/problem?id=1442 开始用二叉排序树写的,TLE了,改成优先队列,过了.. 两个版本都贴一下吧,赚稿费.. #include <stdio.h> #include <queue> #include <vector> using namespace std; priority_queue<int>qmax; priority_queue<int, vector<int>, greater<…
这次我们来讲一讲Treap(splay以后再更) 平衡树是一种排序二叉树(或二叉搜索树),所以排序二叉树可以迅速地判断两个值的大小,当然操作肯定不止那么多(不然我们还学什么). 而平衡树在排序二叉树的基础上主要是增加了一个优化:就是高度较为平衡,并可以动态平衡. 而今天要讲的treap就是一种动态平衡的方法. 首先说声抱歉,因为没有那么多的时间,所以无法把左旋和右旋两种操作具体的讲,但是可以看刘汝佳的蓝书,讲得还是挺清楚的. 现在开始. treap用的是一种比较玄学的方法,就是将每一个点还附上一…
模板题,以后要学splay,大概看一下treap就好了. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; int num[maxn],st[maxn]; struct Treap{ int size; int key,fix; Treap *ch[]; Treap(int key) { size = ; fix = rand(); this->key…
http://poj.org/problem?id=1459 嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点 Status Accepted Time 391ms Memory 1588kB Length 2166 Lang G++ Submitted 2018-05-23 14:43:22 Shared RemoteRunId 18625420 #include <iostream> #include <string.h> #include <cm…
hdu 2544  求点1到点n的最短路  无向图 Sample Input2 1 //结点数 边数1 2 3 //u v w3 31 2 52 3 53 1 20 0 Sample Output32 堆优化Dijstra模板 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include &…
感觉平衡树也没有以前想的那么玄乎,(其实set超好用的),非旋式Treap挺好理解,和可并堆,二叉搜索树有很大联系 推荐博客:http://memphis.is-programmer.com/posts/46317.html 模板也是摘自这位dalao的 #include<bits/stdc++.h> using namespace std; #define maxn 2000005 #define rep(i,x,y) for(int i=x;i<=y;++i) #define dep…
模板题:D错因见注释 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int INF=0x7fffffff; struct treap { treap* lson; treap* rson; int key;//该节点的值 int priority;//优先级 i…
题目链接:http://poj.org/problem?id=1442 本来想复制一下,然后直接sort,结果T了. 在网上看了一下,有用两个队列做的,想了半天,没看懂什么意思.后来模拟一边,总算是懂了. 这里,将要输出的第k小的数存在最小堆中,输出,压入到最大堆中(最大堆是用来存第k小之前的数,更小),循环操作中,要是发现,压人到最小堆中的数,要是比最大堆中的头结点要小,当然要交换啦. #include <stdio.h> #include <string.h> #include…
POJ 最小生成树模板 Kruskal算法 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<limits.h> #include<math.h> #include<queue> #include<st…
这题也能够用树状数组做,并且树状数组姿势更加优美.代码更加少,只是这个Treap树就是求第K大元素的专家--所以速度比較快. 这个也是从那本红书上拿的模板--自己找了资料百度了好久,才理解这个Treap主要的知识,要是自己写真的得写到什么时候啊!.. 然后输入的时候是写n-k+1反着找的,就是这里又浪费了好多时间debug.唉-- #include <iostream> #include <cstdio> #include <fstream> #include <…
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41051   Accepted: 16547 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a mem…
bzoj3580 非旋转treap 在大神教导下发现split一段区间时先split右边再split左边比较好写 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <cctype> using namespace std; typedef long long LL; const i…
type rec=record lc,rc,v,rnd,size,w,fa:longint; end; var n,root,tot,ans,opt,x,i,po:longint; tr:array[0..100000] of rec; procedure rotl(po:longint); var y:longint; begin y:=tr[po].rc; tr[po].rc:=tr[y].lc; if tr[y].lc>0 then tr[tr[y].lc].fa:=po; tr[y].f…
第k大数维护,我推荐Treap..谁用谁知道....                                                           Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5999   Accepted: 2417 Description Our Black Box represents a primitive database. It can save a…
平衡树总是有用的,set由于过度封装没有办法实现找比x小的元素有多少个,这就显得很不方便了,所以封装了个Treap,万一以后用的着呢- -01 #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <vector> #include <cstdio> #include <string> #include <algorithm> usi…
给出三个半平面交的裸题. 不会的上百度上谷(gu)歌(gou)一下. 毕竟学长的语文是体育老师教的.(卡格玩笑,别当真.) 这种东西明白就好,代码可以当模板. //poj1474 Video Surveillance //点集默认顺时针 //算法参考:http://www.cnblogs.com/huangxf/p/4067763.html #include<cstdio> #include<cmath> using namespace std; ; struct point{ d…