题意:给你n个数字,第一个点作为根节点,然后每次插入一个节点,构建一棵平衡二叉树,并输出插入节点后该节点的父节点的值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-;
const int inf =0x7f7f7f7f;
const double pi=acos(-);
const int maxn=; set<int> s;
map<int,int> l;
map<int,int> r; int main()
{
int n,v;
while(~scanf("%d",&n))
{
s.clear();
l.clear();
r.clear(); scanf("%d",&v);
s.insert(v);
for(int i=;i<=n;i++)
{
scanf("%d",&v);
set<int>::iterator it=s.lower_bound(v);
if(it==s.end())
{
it--;
r[*it]=v;
printf("%d ",*it);
s.insert(v);
continue;
} if(l[*it]==)
l[*it]=v;
else{
it--;
r[*it]=v;
}
printf("%d ",*it);
s.insert(v);
}
printf("\n");
}
return ;
}

先前写的爆内存了,,因为最多可以2^1e5,,所以应该改成map,,不过用set模拟BST不太懂啊、、。。链接

  

TTTTTTTTTTTT Codeforces Round #353 (Div. 2) D 平衡二叉树的set模拟 没有很懂的更多相关文章

  1. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  2. Codeforces Round #353 (Div. 2) C Money Transfers

    题目链接: http://www.codeforces.com/contest/675/problem/C 题意: 给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动, ...

  3. Codeforces Round #353 (Div. 2) E. Trains and Statistic 线段树+dp

    题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之 ...

  4. Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树

    题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...

  5. Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)

    题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...

  6. Codeforces Round #353 (Div. 2) D. Tree Construction (二分,stl_set)

    题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时 ...

  7. 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E

    http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...

  8. Codeforces Round #353 (Div. 2) E. Trains and Statistic dp 贪心

    E. Trains and Statistic 题目连接: http://www.codeforces.com/contest/675/problem/E Description Vasya comm ...

  9. Codeforces Round #353 (Div. 2) D. Tree Construction 模拟

    D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...

随机推荐

  1. Centos8 重启网卡方法

    问题情况: 1.虚机centos8 修改为静态ip后,由于网卡网段变更,无法上网 2.最小化安装,没有ifconfig 3.firewalld,selinux关闭 4.ping 不通物理机 根本原因: ...

  2. 如何将本地的项目推送至git仓库

    转载:https://www.jianshu.com/p/31dea20b0084 1.cd projectName probjectName是项目文件夹的名字, 先进入项目文件夹 2.git ini ...

  3. php7.2.1 安装

    yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype ...

  4. 福建工程学院第十四届ACM校赛M题题解 fwt进阶,手推三进制fwt

    第九集,结束亦是开始 题意: 大致意思就是给你n个3进制的数字,让你计算有多少对数字的哈夫曼距离等于i(0<=i<=2^m) 思路: 这个是一个防ak题,做法是要手推公式的fwt 大概就这 ...

  5. 链式栈的C++实现

    这是去年的内容,之前放在github的一个被遗忘的reporsity里面,今天看到了就拿出来 #include<iostream> #include<string> using ...

  6. Bat批处理文件入门

    这个东西吧,感觉在使用windows时作用不是很大,毕竟在windows环境下命令行确实用的比较少,但有时候也会用到,比如测试算法程序时使用批处理+文件可以省去每次手动输入.赶巧最近对批处理也比较感兴 ...

  7. pytorch中的torch.repeat()函数与numpy.tile()

    repeat(*sizes) → Tensor Repeats this tensor along the specified dimensions. Unlike expand(), this fu ...

  8. Spring Boot整合actuator实现监控管理

    Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...

  9. QQ恶搞 - 让艾特你的人语无伦次

    效果图: 实现过程: 代码: ‮ 将上面的代码复制添加到你的群名片后面即可. 原理解析: 这个代码是一个Unicode控制字符 - RLO,它可以控制在它后面的所有文本都已倒序的方式显示.在qq群艾特 ...

  10. Java的clone方法

    现在有User类:(Getter和Setter省略) public class User implements Cloneable { private String name; private int ...