poj3481
题解:
splay操作
读入速度太慢,导致超时。。。
用字符串gets操作
代码:
#pragma GCC optimize(2)
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=;
char s[];
int pre[N],tot,q[],y,data[N],z,size[N];
int aans[N],p,c[N][],root,n,m,x;
void rot(int x)
{
int y=pre[x],k=(c[y][]==x);
size[y]=size[c[y][k]]+size[c[x][k]]+;
size[x]=size[c[x][!k]]+size[y]+;
c[y][!k]=c[x][k];
pre[c[y][!k]]=y;
pre[x]=pre[y];
if(pre[y])c[pre[y]][c[pre[y]][]==y]=x;
c[x][k]=y;pre[y]=x;
}
void splay(int x,int g)
{
for(int y=pre[x];y!=g;rot(x),y=pre[x])
if(pre[y]!=g)rot((x==c[y][])==(y==c[pre[y]][])?y:x);
if(g==)root=x;
}
void insert(int x,int q)
{
int y=root;
while(c[y][x>data[y]]) y=c[y][x>data[y]];
data[++tot]=x;aans[tot]=q;
c[tot][]=c[tot][]=;
pre[tot]=y;
if(y)c[y][x>data[y]]=tot;
splay(tot,);
}
int findmin()
{
int y=root;
while (c[y][])y=c[y][];
if (y==root)root=c[y][],pre[c[y][]]=;
else c[pre[y]][]=c[y][],pre[c[y][]]=pre[y];
return aans[y];
}
int findmax()
{
int y=root;
while (c[y][])y=c[y][];
if (y==root)root=c[y][],pre[c[y][]]=;
else c[pre[y]][]=c[y][],pre[c[y][]]=pre[y];
return aans[y];
}
int main()
{
while ()
{
gets(s);
if (s[]=='')return ;
if (s[]=='')
{
int z=,y=;
int i;
for (i=;s[i]>=''&&s[i]<='';i++)z=z*+s[i]-;
i++;
for (;s[i]>=''&&s[i]<='';i++)y=y*+s[i]-;
insert(y,z);
}
if (s[]=='')printf("%d\n",findmin());
if (s[]=='')printf("%d\n",findmax());
}
}
poj3481的更多相关文章
- splay poj3481
三种操作 1 k p 插入一个点 2 输出p最大对应的k 删除这个点 3 输出p最小对应的k 删除这个点 splay 维护一下 一不小心就会超时 #include<stdio.h> ...
- 【POJ3481】【splay】Double Queue
Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...
- poj3481 splaytree模板题
找不到错在哪里,先留着吧 /* splay是以键值排序的! 三个操作:1 a b,z增加键值为b的点,值为a 2,查询最大值 3,查询最小值 需要的操作:rotate,splay,insert,fin ...
- [POJ3481]Double Queue
Problem 0 结束操作 1 K P 将一个数K以优先级P加入 2 取出优先级最高的那个数 3 取出优先级最低的那个数 Solution Splay模板题 Notice 是输出数而不是输出优先级. ...
- POJ-3481 Double Queue (splay)
The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped w ...
- poj3481(splay tree 入门题)
平衡树都能做. // // main.cpp // splay // // Created by 陈加寿 on 16/3/25. // Copyright © 2016年 chenhuan001. A ...
- POJ-3481 Double Queue,Treap树和set花式水过!
Double Queue 本打算学二叉树,单纯的二叉树感觉也就那几种遍历了, 无意中看到了这个题,然后就 ...
- 三大平衡树(Treap + Splay + SBT)总结+模板[转]
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #i ...
- 平衡树初阶——AVL平衡二叉查找树+三大平衡树(Treap + Splay + SBT)模板【超详解】
平衡树初阶——AVL平衡二叉查找树 一.什么是二叉树 1. 什么是树. 计算机科学里面的树本质是一个树状图.树首先是一个有向无环图,由根节点指向子结点.但是不严格的说,我们也研究无向树.所谓无向树就是 ...
随机推荐
- Python3基础 逻辑运算 and or not 示例
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- aws相关文档
使用 IAM 角色授予对 Amazon EC2 上的 AWS 资源的访问权 https://docs.aws.amazon.com/zh_cn/sdk-for-java/v1/developer-gu ...
- ZOJ 3329 One Person Game (经典概率dp+有环方程求解)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329 题意:现在有三个骰子,分别有k1,k2和k3面,面上的点就是1~ki ...
- HDU 1548 A strange lift (Dijkstra)
https://vjudge.net/problem/HDU-1548 题意: 电梯每层有一个不同的数字,例如第n层有个数字k,那么这一层只能上k层或下k层,但是不能低于一层或高于n层,给定起点与终点 ...
- python enumerate用法总结--转载
enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...
- Linux批量更改文件后缀-转载
一.rename解决 1. Ubuntu系统下 rename 's//.c//.h/' ./* 把当前目录下的后缀名为.c的文件更改为.h的文件 2. CentOS5.5系统下 rename . ...
- linux——通信指令学习简单笔记
一: 指令名称:write 指令所在路径:/usr/bin/write 执行权限:All User 语法:write <用户名> 功能描述:向另外一个用户发信息,以Ctrl+D作 为结束 ...
- shell 余弦值转角度
范例:余弦值转角度 用 bc -l 计算,可以获得高精度: $ export cos=0.996293; echo "scale=100; a(sqrt(1-$cos^2)/$cos)*18 ...
- Ubuntu 定时任务
一.cron相关命令 #重载cron sudo service cron reload #查看cron状态 service cron status #查看cron pid pidof ...
- cqlsh 一个错误
C:\Users\jasqia>cqlsh 10.215.70.158 1433Can't detect Python version! http://zqhxuyuan.github.io/2 ...