Problem

0 结束操作

1 K P 将一个数K以优先级P加入

2 取出优先级最高的那个数

3 取出优先级最低的那个数

Solution

Splay模板题

Notice

是输出数而不是输出优先级。

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9, N = 1000000;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
int point = 0, root;
struct node
{
int val[N + 5], son[2][N + 5], parent[N + 5], label[N + 5]; void Rotate(int x, int &rt)
{
int y = parent[x], z = parent[y];
int l = (son[1][y] == x), r = 1 - l;
if (y == rt) rt = x;
else if (son[0][z] == y) son[0][z] = x;
else son[1][z] = x;
parent[x] = z;
parent[son[r][x]] = y, son[l][y] = son[r][x];
parent[y] = x, son[r][x] = y;
} void Splay(int x, int &rt)
{
while (x != rt)
{
int y = parent[x], z = parent[y];
if (y != rt)
{
if ((son[0][z] == y) ^ (son[0][y] == x))
Rotate(x, rt);
else Rotate(y, rt);
}
Rotate(x, rt);
}
} void Insert(int &u, int x, int y, int last)
{
if (u == 0)
{
u = ++point;
val[u] = y, parent[u] = last, label[u] = x;
Splay(u, root);
}
else
{
if (y > val[u]) Insert(son[1][u], x, y, u);
else if (y < val[u]) Insert(son[0][u], x, y, u);
}
} void Delete(int x)
{
Splay(x, root);
if (son[0][x] * son[1][x] == 0) root = son[0][x] + son[1][x];
else
{
int t = son[1][x];
while (son[0][t] != 0) t = son[0][t];
Splay(t, root);
son[0][t] = son[0][x], parent[son[0][x]] = t;
}
parent[root] = 0;
} int Find_max()
{
int t = root;
while (son[1][t] != 0) t = son[1][t];
return t;
} int Find_min()
{
int t = root;
while (son[0][t] != 0) t = son[0][t];
return t;
}
}Splay_tree;
int main()
{
int H_H;
while (~scanf("%d", &H_H) && H_H)
{
int x, y;
switch (H_H)
{
case 1:
x = read(), y = read();
Splay_tree.Insert(root, x, y, 0);
break;
case 2:
x = Splay_tree.Find_max();
printf("%d\n", Splay_tree.label[x]);
Splay_tree.Delete(x);
break;
case 3:
y = Splay_tree.Find_min();
printf("%d\n", Splay_tree.label[y]);
Splay_tree.Delete(y);
break;
}
}
}

[POJ3481]Double Queue的更多相关文章

  1. POJ-3481 Double Queue,Treap树和set花式水过!

                                                    Double Queue 本打算学二叉树,单纯的二叉树感觉也就那几种遍历了, 无意中看到了这个题,然后就 ...

  2. POJ-3481 Double Queue (splay)

    The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped w ...

  3. poj 3841 Double Queue (AVL树入门)

    /****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...

  4. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  5. POJ 3481 Double Queue STLmap和set新学到的一点用法

    2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...

  6. 【Map】Double Queue

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13258   Accepted: 5974 Des ...

  7. POJ 3481 Double Queue(STL)

    题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身 ...

  8. POJ 3481 Double Queue(set实现)

    Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Buchares ...

  9. POJ 3481 Double Queue(Treap模板题)

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Des ...

随机推荐

  1. 牛客OI周赛6-提高组 A 大法师与魔法石

    大法师与魔法石 思路: 对于一个ai, 它可以构成区间[ai/v, ai] 假设和它相邻的为aj, 那么ai 和 aj 构成的区间为[(ai+aj) / v, ai+aj] 那么这两个区间能合并的条件 ...

  2. ie67的冷知识

    1. _display:inline;是什么意思 只有ie6认识带下划线的,一般这种写法是用来消除ie6对margin双倍的bug的,比如你写margin-left:10px;那么ie6下显示的是20 ...

  3. 创建.ignore文件

    方法一:1. 在需要创建 .gitignore 文件的文件夹, 右键选择Git Bash 进入命令行,进入项目所在目录.如:(cd /d/git/project) 2. 输入 touch .gitig ...

  4. LeetCode--003--无重复字符的最长子串

    问题描述: 给定一个字符串,找出不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 无重复字符的最长子串是 "abc" ...

  5. 关于java和c语言中,变量重名问题

    请看下面的两段代码: #include <iostream>#include <cstdio>#include <cstring> using namespace ...

  6. Dedecmsv5.7整合ueditor 图片上传添加水印

    最近的项目是做dedecmsv5.7的二次开发,被要求上传的图片要加水印,百度ueditor编辑器不支持自动加水印,所以,找了很多资料整合记录一下,具体效果图 这里不仔细写dedecmsv5.7 整合 ...

  7. Luffy之前端项目部署搭建

    1. 搭建前端项目 1.1 创建项目目录 cd 项目目录 vue init webpack lufei 根据需要在生成项目时,我们选择对应的选项, 效果: 根据上面的提示,我们已经把vue项目构建好了 ...

  8. python基础之变量以及if语句

    1.变量 1.1定义:变量是一种介质,是将一些值暂时存储在内存中,方便后续程序调用.可将其看作容器但其内部的东西是可变化的. 1.2 变量的命名规则: 1.变量的命名只能由数字,字母,下划线构成. 2 ...

  9. 如何开发mis系统--整理

    1.含义: 所谓MIS(管理信息系统--Management Information System)系统,主要指的是进行日常事务操作的系统.这种系统主要用于管理需要的记录,并对记录数据进行相关处理,将 ...

  10. python-django rest framework框架之渲染器

    渲染器 看到的页面时什么样子的,返回数据. restframework中默认就是下面 这两个render类,它的内部实现原理是拿url中的后缀名 .json 和类中的format字段进行比较,如果re ...