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. 什么是树. 计算机科学里面的树本质是一个树状图.树首先是一个有向无环图,由根节点指向子结点.但是不严格的说,我们也研究无向树.所谓无向树就是 ...
随机推荐
- WideCharToMultiByte和MultiByteToWideChar函数的用法(转载)
出处:http://www.cnblogs.com/gakusei/articles/1585211.html 为了支持Unicode编码,需要多字节与宽字节之间的相互转换.这两个系统函数在使用时需要 ...
- P3939 数颜色
目录 题目 思路1(待修莫队) 思路2(vector+二分) 代码1 代码2 题目 P3939 数颜色 思路1(待修莫队) 哇,这不是莫队模板题吗 3e5,TLE45分 不行 我有信仰啊 pow(n, ...
- <OFFER> 06_PrintListInReversedOrder
#include<stack> #include "List.h" void PrintListReversingly_Iteratively(ListNode* pH ...
- POJ 3480 John(SJ定理博弈)题解
题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考 ...
- 【第三十二章】 elk(3)- broker架构 + 引入logback
实际中最好用的日志框架是logback,我们现在会直接使用logback通过tcp协议向logstash-shipper输入日志数据.在上一节的基础上修改!!! 一.代码 1.pom.xml 1 &l ...
- 风景区的面积及道路状况分析问题 test
参考文献: https://wenku.baidu.com/view/b6aed86baf1ffc4ffe47ac92.html #include <bits/stdc++.h> us ...
- Unity3D学习笔记(二十一):InputFiled、Dropdown、Scroll Rect、Mask
InputFiled组件(输入框) Text Component(显示内容):显示输入内容的Text的组件 Text(输入内容):输入的文本内容 Character Limit:字符数量限值,0是无限 ...
- 【jdk源码分析】java.lang.Appendable
1.概述 public interface Appendable 能够被添加 char 序列和值的对象.如果某个类的实例打算接收取自 Formatter 的格式化输出,那么该类必须实现 Appenda ...
- ZOJ 3869 Ace of Aces
There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep univer ...
- 【Python】【内置函数】【bytes&bytearray&str&array】
[bytes] 英文文档: class bytes([source[, encoding[, errors]]]) Return a new “bytes” object, which is an i ...