codeforces 675D Tree Construction set
转自:http://blog.csdn.net/qwb492859377/article/details/51447350
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=1e5+;
typedef pair<int,int> pii;
set<pii>s;
int fa[N];
bool l[N],r[N];
int main(){
int n;
scanf("%d",&n);
set<pii>::iterator it1,it2;
pii tmp;
scanf("%d",&tmp.first),tmp.second=;
s.insert(tmp);
for(int i=;i<=n;++i){
scanf("%d",&tmp.first);
tmp.second=i;
it2=s.lower_bound(tmp);
if(it2==s.end()){
it1=it2;it1--;
fa[i]=(*it1).first;
r[(*it1).second]=true;
}
else {
if(it2==s.begin()){
fa[i]=(*it2).first;
l[(*it2).second]=true;
}
else{
it1=it2;it1--;
if(!r[(*it1).second]){
fa[i]=(*it1).first;
r[(*it1).second]=true;
}
else{
fa[i]=(*it2).first;
l[(*it2).second]=true;
}
}
}
s.insert(tmp);
}
for(int i=;i<n;++i)
printf("%d ",fa[i]);
printf("%d\n",fa[n]);
return ;
}
codeforces 675D Tree Construction set的更多相关文章
- Codeforces 675D Tree Construction Splay伸展树
链接:https://codeforces.com/problemset/problem/675/D 题意: 给一个二叉搜索树,一开始为空,不断插入数字,每次插入之后,询问他的父亲节点的权值 题解: ...
- CodeForces 675D Tree Construction
递归,$RMQ$. 因为$n$较大,可以采用递归建树的策略. 对每一个点标一个$id$.然后按照$v$从小到大排序,每一段$[L,R]$的根节点就是$id$最小的那个. 因为二叉搜索树可能是一条链,所 ...
- CF 675D——Tree Construction——————【二叉搜索树、STL】
D. Tree Construction time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【CF 675D Tree Construction】BST
题目链接:http://codeforces.com/problemset/problem/675/D 题意:给一个由n个互异整数组成的序列a[],模拟BST的插入过程,依次输出每插入一个元素a[i] ...
- codeforces 675D D. Tree Construction(线段树+BTS)
题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 模拟
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...
- 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction
Tree Construction Problem's Link ------------------------------------------------------------------- ...
- HDOJ 3516 Tree Construction
四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- 【Codeforces 675D】Tree Construction
[链接] 我是链接,点我呀:) [题意] 依次序将数字插入到排序二叉树当中 问你每个数字它的父亲节点上的数字是啥 [题解] 按次序处理每一个数字 对于数字x 找到最小的大于x的数字所在的位置i 显然, ...
随机推荐
- Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace
被这个问题折磨着很久:参考: http://have23.iteye.com/blog/1340777 (cfx 与 spring 整合的时候出现的问题: org.springframework.be ...
- Linux 学习guideline
记得在中国人气和高手最多的linuxform上看到的一句话. 现在自己的书架上以后lkd2+ldd3+情景分析,再加上它ulk3,书架的linux kernel的四库全书已经凑齐,很充实. lkd2: ...
- SULogger:iOS日志可视化工具
前言 debug对于咋们程序员来说家常便饭,但有时候我们会遇到一种情况:开发某个功能时,需要在某个特定场景下进行调试,而这个场景并没有MacBook来进行连接debug,偏偏我们需要获得调试时的一些信 ...
- 实例学习Bloom Filter
0. 科普1. 为什么需要Bloom Filter2. 基本原理3. 如何设计Bloom Filter4. 实例操作5. 扩展 0. 科普 Bloom Filter是由Bloom在1970年提出的一种 ...
- openfire开发
openfire github地址:https://github.com/igniterealtime/Openfire 1.下载源代码:http://www.igniterealtime.org/d ...
- Java中常见几种数据库连接方法
1:引入java.sql数据包; import java.sql.*; 2:加载JDBC驱动程序 Class.forName(JDBC驱动包的名字).newInstance(); 3:产生Co ...
- 用imagemagick和tesseract-ocr破解简单验证码
用imagemagick和tesseract-ocr破解简单验证码 Tesseract-ocr据说辨识程度是世界排名第三,可谓神器啊. 准备工作: 1.安装tesseract-ocr sudo apt ...
- js自动判断浏览器类型跳转到手机版
//电脑版头部写法:<script language="javascript"> function is_mobile() { var regex_match = /( ...
- web交互方式
轮询:客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接. 优点:后端程序编写比较容易. 缺点:请求中有大半是无用,浪费带宽和服务器资源. 实例:适于小型应用. 长轮询:客 ...
- I.MX6 Ubuntu core porting
/*********************************************************************** * I.MX6 Ubuntu core porting ...