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基础 __setattr__ 在属性被赋值的时候,新增提示功能
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Avito Cool Challenge 2018
考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...
- 【TCP/IP详解 卷一:协议】第二十三章 TCP的保活定时器
本章介绍保活定时器. 在 TCP 的三握四挥 章节中,我们介绍了 处在 TIME_WAIT 的 2MSL定时器:在 TCP的超时与重传 章节中,我们介绍了 重传定时器:在上一章节中,我们介绍了 防止死 ...
- Gym - 100345H Settling the Universe Up(bitset)
https://vjudge.net/problem/Gym-100345H 题意: 给出一个图,求图中u能到达v的对数,并且u<v.并且会有更新和查询操作. 思路: bitset直接暴力,对于 ...
- React Native 的组件之底部导航栏 TabBarIOS(一)
import React,{Component}from 'react'; import { AppRegistry, StyleSheet, Text, View, TabBarIOS, } fro ...
- [ios][swift]UIButton
参考:http://www.hangge.com/blog/cache/detail_529.html
- RetinaNet论文理解
引言 介绍 目前精度高的检测器都是基于two-stage,proposal-driven机制,第一阶段生成稀疏的候选对象位置集,第二阶段使用CNN进一步将每个候选位置分为前景或者背景以及确定其类别: ...
- _proto_和prototype区别
推荐一篇阅读:http://cometosay.com/2016/08/31/js-proto.html es中创建对象的方法 (1)对象字面量的方式 (2)new 的方式 (3)ES5中的`Obje ...
- C#实现的UDP收发请求工具类实例
本文实例讲述了C#实现的UDP收发请求工具类.分享给大家供大家参考,具体如下: 初始化: ListeningPort = int.Parse(ConfigurationManager.AppSetti ...
- 42 前端HTML
HTML 1. 概念 HTML 超文本标记语言(Hypertext Markup Language, HTML)是一种用于创建网页的标记语言 . 2.标签 Meta标签 <me ...