TTTTTTTTTTTT Codeforces Round #353 (Div. 2) D 平衡二叉树的set模拟 没有很懂
题意:给你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模拟 没有很懂的更多相关文章
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #353 (Div. 2) C Money Transfers
题目链接: http://www.codeforces.com/contest/675/problem/C 题意: 给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动, ...
- 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的最短距离之 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树
题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction (二分,stl_set)
题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时 ...
- 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E
http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...
- 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 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 模拟
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...
随机推荐
- [转帖]Oracle 数据库官方不支持VMWare
Oracle 数据库官方不支持VMWare [日期:2014-05-13] 来源:Linux社区 作者:myhuaer [字体:大 中 小] https://www.linuxidc.com/L ...
- 【监控实践】【4.4】使用DMV和函数监控数据库状态和资源使用
1.查看当前实例运行进程 -- 核心DMV.函数.系统SP:/* 所有进程请求:sys.dm_exec_requests 所有进程与连接:sys.sysprocesses 系统函数,查看sql:sys ...
- hive与hbase的交互简要示意
建表 create external table if not exists hive2hbase( id int, ---> 对应hbase的rowkey (即下面的:key) age int ...
- jinja2 模板相关
安装 pip install jinja2 配置模板 settings.py 60行左右 TEMPLATES = [ { 'BACKEND': 'django.template.backends.dj ...
- CentOS 7系统安装Jenkins
一.jenkins 介绍 Jenkins是一个开源的.可扩展的持续集成.交付.部署(软件/代码> 的编译.打包.部署)基于web界面的平台. 简单说,就是各种项目的"自动化" ...
- Dubbo架构
原文链接http://dubbo.apache.org 架构图 节点角色说明 节点 角色说明 Provider 暴露服务的服务提供方 Consumer 调用远程服务的服务消费方 Registry 服务 ...
- 丑陋的 shell 来一遍
学习使人进步,好记性不如烂笔头 在线正则 在线正则 ^(.)(.).*?\2\1$ 正式开始总结 cat 反过来读取文件 tac file.txt nl --> number line 如 ca ...
- Nginx默认配置语法
Nginx默认配置语法 1. 我们进入 /etc/nginx/目录下,打开 nginx.conf文件 2. 我们来解析下 这里面标签和各模块的作用 # 设置nginx服务的系统使用用户 user ...
- Swift(一)语言介绍
Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题. Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在其中 ...
- date( ) 日期函数
date('Y-m-dT2:00') 实际时间为14:00 date('Y-m-d 2:00') 实际时间为2:00 扩展:每天的时间戳秒数为 86400