链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2761

思路: map标记

实现代码:

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
int t,n,x;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = ;i <= n;i ++){
scanf("%d",&x);
mp[x]++;
if(mp[x]==) printf("%d ",x);
}
printf("\n");
mp.clear();
}
}

这道题也可以用平衡树写,虽然也很水/////

Treap写法:

实现代码:

#include<bits/stdc++.h>
using namespace std;
const int M = 1e5 +;
struct node{
int l,r,siz,cnt,wt,val;
}t[M];
int cnt,flag; void lt(int &k){
int tmp = t[k].r;
t[k].r = t[tmp].l;
t[tmp].l = k;
t[tmp].siz = t[k].siz;
t[k].siz = t[t[k].l].siz + t[t[k].r].siz + t[k].cnt;
k = tmp;
} void rt(int &k){
int tmp = t[k].l;
t[k].l = t[tmp].r;
t[tmp].r = k;
t[tmp].siz = t[k].siz;
t[k].siz = t[t[k].l].siz + t[t[k].r].siz + t[k].cnt;
k = tmp;
} void Insert(int &k,int num){
if(!k){
k = ++cnt;
t[k].wt = rand();
t[k].val = num;
t[k].cnt = t[k].siz = ;
return ;
}
++t[k].siz;
if(num == t[k].val){
++t[k].cnt;
flag = ;
return ;
}
if(num < t[k].val){
Insert(t[k].l,num);
if(t[t[k].l].wt < t[k].wt) rt(k);
}
else{
Insert(t[k].r,num);
if(t[t[k].r].wt < t[k].wt)
lt(k);
}
} int main()
{
int T,n,x,root;
scanf("%d",&T);
while(T--){
memset(t,,sizeof(t));
root = cnt = ;
scanf("%d",&n);
for(int i = ;i <= n;i ++){
cin>>x;
flag = ;
Insert(root,x);
if(!flag) printf("%d ",x);
}
printf("\n");
}
return ;
}

bzoj 2761: [JLOI2011]不重复数字 (map||Treap)的更多相关文章

  1. bzoj 2761 [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3210  Solved: 1186[Submit][Sta ...

  2. BZOJ 2761: [JLOI2011]不重复数字 水题

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2100  Solved: 809 题目连接 http:// ...

  3. BZOJ 2761: [JLOI2011]不重复数字 set

    Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...

  4. BZOJ 2761: [JLOI2011]不重复数字 hash哈希

    题目就不贴了 点我看题 题意:这题题意很简明,就是给一个序列,把序列里相同的删掉,然后输出,按原数列顺序. 思路:这题之前QZZ和ZN大神犇叫我去做,辣时还不会hash,就留着了.最近某夏令营学会了h ...

  5. bzoj 2761: [JLOI2011]不重复数字【hash】

    map会T,双hash会冲突--于是非酋写了个三hash #include<iostream> #include<cstdio> #include<cstring> ...

  6. bzoj 2761: [JLOI2011]不重复数字

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...

  7. 2761: [JLOI2011]不重复数字(平衡树)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2133  Solved: 825[Submit][Stat ...

  8. 2761: [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1770  Solved: 675[Submit][Stat ...

  9. 【BZOJ】2761: [JLOI2011]不重复数字(set+巨水题+超坑题)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include < ...

随机推荐

  1. vue-area-linkage Vue省市区三级列表联动插件使用

    官方演示地址 // v5及之后的版本 数据依赖于area_data npm i --save vue-area-linkage area-data import Vue from 'vue'; imp ...

  2. elasticsearch(6.2.3)安装Head插件

    一.安装elasticsearch,参照:https://www.cnblogs.com/dyh004/p/8872443.html 二.安装nodejs,参照:https://www.runoob. ...

  3. POJ - 2528 区间离散化,线段树区间修改,区间询问

    这个题非常有意思的地方是,我们发现区间[1,4]和[5,8]是紧挨着的,因为这个的数代表的是一段区间,原本我们对于普通的离散, a[1]=1,a[2]=5,a[3]=6,a[4]=8;数组下标就是重新 ...

  4. 全局关键字搜索:Element UI Table内容过滤\jQuery过滤器fastLiveFilter插件\BootstrapVue插件;

    ```html data:{ resultMaster: [], otableData:[], schfilter:'' } watch: { schfilter: function(val, old ...

  5. 15-分析Ajax请求并抓取今日头条街拍美图

    流程框架: 抓取索引页内容:利用requests请求目标站点,得到索引网页HTML代码,返回结果. 抓取详情页内容:解析返回结果,得到详情页的链接,并进一步抓取详情页的信息. 下载图片与保存数据库:将 ...

  6. 《梦断代码》Scott Rosenberg著(二)

    书中有一段说的是一个闪烁缺陷——在改变某软件中某个窗体的尺寸时,屏幕会闪烁一秒钟左右.虽然该缺陷不会影响程序运行,但它不符合作者的审美观,历时六个多月仍然没能修正.其实在日常的编程中也有许多小bug的 ...

  7. Oracle列转行函数LISTAGG()

    --Oracle列转行函数LISTAGG() with tb_temp as( select 'China' 国家,'Wuhan' 城市 from dual union all select 'Chi ...

  8. scala mkstring

    如果你想要把集合元素转化为字符串,可能还会添加分隔符,前缀,后缀. Solution 使用mkString方法来打印一个集合内容,下面给一个简单的例子: scala> val a = Array ...

  9. python中的__init__和__new__的区别

    一.__init__ 方法是什么?(init前后的线是双下划线) 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例 ...

  10. python之路--MySQL多表查询

    一 介绍 我们在写项目的时候一般都会建一个数据库,数据库里面会存很多的表,不可能把所有的数据都放在一张表里,因为分表来存数据节省空间,数据的组织结构更清晰,解耦和程度更高,但是这些表本质上还不是一个整 ...