【bzoj2761】【JLOI2011】【不反复数字】【平衡树】
Description
Input
Output
Sample Input
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
Sample Output
1 2 3 4 5 6
HINT
对于30%的数据,1 <= N <= 100,给出的数不大于100。均为非负整数;
对于50%的数据。1 <= N <= 10000,给出的数不大于10000,均为非负整数;
对于100%的数据,1 <= N <= 50000。给出的数在32位有符号整数范围内。
提示:
因为数据量非常大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。
题解:裸平衡树。
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,t,x;
bool f;
struct Node{
Node*ch[2];
int r,s,v;
Node(int v):v(v){ch[0]=ch[1]=NULL;r=rand();}
int cmp(int x){
if (x==v) return -1;
else return (x<v? 0:1);
}
};
Node* root;
void rotata(Node* &o,int d)
{
Node*k=o->ch[d^1];o->ch[d^1]=k->ch[d];k->ch[d]=o;o=k;
}
void insert(Node* &o,int x)
{
if (o==NULL) o=new Node(x);
else
{
int d=o->cmp(x);
if (d==-1) {f=false;return;}
if (d!=-1)
{
insert(o->ch[d],x);
if (o->ch[d]->r>o->r) rotata(o,d^1);
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
root=NULL;
scanf("%d%d",&n,&x);f=true;
insert(root,x);
if (f) printf("%d",x);
for (int i=1;i<n;i++)
{
f=true;scanf("%d",&x);
insert(root,x);
if (f) printf(" %d",x);
}
printf("\n");
}
}
【bzoj2761】【JLOI2011】【不反复数字】【平衡树】的更多相关文章
- [BZOJ2761][JLOI2011]不重复数字
[BZOJ2761][JLOI2011]不重复数字 试题描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复 ...
- [BZOJ2761] [JLOI2011] 不重复数字 (set)
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- BZOJ2761:[JLOI2011]不重复数字(map)
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- BZOJ2761: [JLOI2011]不重复数字【set】【傻逼题】
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- [BZOJ2761] [JLOI2011] 不重复数字 (C++ STL - set)
不重复数字 题目: 给出N个数,要求把其中重复的去掉,只保留第一次出现的数.例如,给出的数 为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 1 ...
- bzoj2761: [JLOI2011]不重复数字(hash)
题目大意:给出N个数,要求把其中重复的去掉,只保留第一次出现的数.例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. ...
- 【set】bzoj2761 [JLOI2011]不重复数字
set去重. #include<cstdio> #include<set> using namespace std; set<int>S; ],b[],en; in ...
- [BZOJ2761][JLOI2011]不重复数字 暴力
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2761 直接暴力. #include<cstdio> #include<c ...
- 2761: [JLOI2011]不重复数字(平衡树)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2133 Solved: 825[Submit][Stat ...
- BZOJ2761 不重复的数字 【treap】
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 5517 Solved: 2087 [Submit][S ...
随机推荐
- 树状数组 gcd 查询 Different GCD Subarray Query
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- EasyUI 打印当前页
function CommonPrint(printDatagrid, type) { var tableString = '<table cellspacing="0" c ...
- vue v-dialogDrag: 弹窗拖拽
Vue.directive('dialogDrag', { inserted:function(el) { const dragDom = el.querySelector('.jsPropupLay ...
- Redis的持久化——RDB
前面说到redis的三大特性:缓存.分布式内存数据库.持久化,所以今天将为大家介绍redis的两种数据持久化技术RDB和AOF, 先介绍RDB吧. 一.RDB是什么? 1.RDB全称redis dat ...
- 【2018.12.10】NOI模拟赛3
题目 WZJ题解 大概就是全场就我写不过 $FFT$ 系列吧……自闭 T1 奶一口,下次再写不出这种 $NTT$ 裸题题目我就艹了自己 -_-||| 而且这跟我口胡的自创模拟题 $set1$ 的 $T ...
- 使用反射获取类中的属性(可用于动态返回PO类的列,当做表格的表头)
//利用反射取类中的属性字段 try { Class clazz = Class.forName("houji.bean.model.TaskModel"); Field[] fi ...
- Eclipse 语言文件下载地址
http://www.eclipse.org/babel/downloads.php 更改配色: 安装新软件: http://eclipse-color-theme.github.com/update
- 用CSS3变形创建半圆形导航
http://www.xuanfengge.com/create-a-semicircle-with-css3-variant-navigation.html demo:http://tympanus ...
- JS标签获取另一个页面传过来的href值
a href=b.html?id=楼主>B页面</a>b.html中的获取函数:function getParam(){C1=window.location.href.split(& ...
- 转:c++ 11 新特性
声 明:本文源自 Danny Kalev 在 2011 年 6 月 21 日发表的<The Biggest Changes in C++11(and Why You Should Care)&g ...