转自: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的更多相关文章

  1. Codeforces 675D Tree Construction Splay伸展树

    链接:https://codeforces.com/problemset/problem/675/D 题意: 给一个二叉搜索树,一开始为空,不断插入数字,每次插入之后,询问他的父亲节点的权值 题解: ...

  2. CodeForces 675D Tree Construction

    递归,$RMQ$. 因为$n$较大,可以采用递归建树的策略. 对每一个点标一个$id$.然后按照$v$从小到大排序,每一段$[L,R]$的根节点就是$id$最小的那个. 因为二叉搜索树可能是一条链,所 ...

  3. CF 675D——Tree Construction——————【二叉搜索树、STL】

    D. Tree Construction time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 【CF 675D Tree Construction】BST

    题目链接:http://codeforces.com/problemset/problem/675/D 题意:给一个由n个互异整数组成的序列a[],模拟BST的插入过程,依次输出每插入一个元素a[i] ...

  5. codeforces 675D D. Tree Construction(线段树+BTS)

    题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...

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

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

  7. 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction

    Tree Construction Problem's Link ------------------------------------------------------------------- ...

  8. HDOJ 3516 Tree Construction

    四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  9. 【Codeforces 675D】Tree Construction

    [链接] 我是链接,点我呀:) [题意] 依次序将数字插入到排序二叉树当中 问你每个数字它的父亲节点上的数字是啥 [题解] 按次序处理每一个数字 对于数字x 找到最小的大于x的数字所在的位置i 显然, ...

随机推荐

  1. 《架构探险——从零开始写Java Web框架》这书不错,能看懂的入门书

    这书适合我. 哈哈,结合 以前的知识点,勉强能看懂. 讲得细,还可以参照着弄出来. 希望能坚持 完成啦... 原来,JSTL就类似于DJANGO中的模板. 而servlet类中的res,req,玩了D ...

  2. Python中Lambda, filter, reduce and map 的区别

    Lambda, filter, reduce and map Lambda Operator Some like it, others hate it and many are afraid of t ...

  3. [hackerrank]Manasa and Stones

    https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones 简单题. #include<iostream> us ...

  4. 【Linux高频命令专题(9)】ls

    ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  5. NGUI中Button与原生2D精灵的混合使用

    一些废话 每一篇的首段都是这个“一些废话”,原因是我太能逼逼了,不逼逼一些废话我就觉得难受.这是我第四篇关于Unity的博文,前两篇还是去年写的,“从一点儿不会开始”系列,类似教程和学习笔记的博文,这 ...

  6. python os.stat() 和 stat模块详解

    stat 系统调用时用来返回相关文件的系统状态信息的. 首先我们看一下stat中有哪些属性: >>> import os >>> print os.stat(&qu ...

  7. jQuery通知插件 -- noty

    noty是一个jQuery的通知(信息提示)插件,灵活轻便,是一个非常棒的用于替代传统提示对话框的插件. 当前最新版本为2.1.0: 从https://github.com/needim/noty 可 ...

  8. Filter过滤非法字符

    示例:定义一个Filter,用于用户发言中出现的“晕”字,即如果没有这个字则允许发言,如果有这个字则不允许发言并提示错误. CharForm.jsp <%@ page language=&quo ...

  9. 成为一个PHP专家:缺失的环节

    这一篇文章是“Becoming a PHP Professional”系列 4 篇博文中的第 1 篇. 当浏览各类与PHP相关的博客时,比如Quora上的问题,谷歌群组,简讯和杂志,我经常注意到技能的 ...

  10. mysql 插入汉字 异常 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name'

    今天使用mysql出现 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name' 异常 通过查找问题,发现是字段编码不支 ...