转自: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. Sina App Engine(SAE)入门教程(7)- Storage使用

    参考阅读 sae storage api 文档 Storage 说明文档 Storage 大文件上传说明 storage是什么? 因为sae禁用了代码环境的本地读写,但是在网站运行的过程中,必定会出现 ...

  2. MVC下基于DotNetOpenAuth 实现SSO单点登录

    具体官网可以查看:http://dotnetopenauth.net/,托管地址:https://github.com/DotNetOpenAuth/DotNetOpenAuth 可能需要FQ 博客园 ...

  3. [Unity菜鸟] FBX模型动画提取

    角色已经人形化(Humanoid)了,那它的动画可以用在其它的模型上了也就是可以共用一套模型动画了,但是你有没有发现那动画是和fbx模型绑在一起的,没关系你可以选中这几个动画文件按Contrl+D就可 ...

  4. No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 问题

    maven编译项目时出错,提示信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3 ...

  5. MyEclipse +Tomcat 异常操作

    安装完MyEclipse 2014,用JAX-WS的方式写了一个小段Web Service,用MyEclipse 自带的 Tomcat 部署没有问题,用我自己的,却出现下面的错误: java.lang ...

  6. 最受欢迎的ASP.NET的CMS下载

    1. Umbraco 项目地址 下载 Umbraco是一个开放源码的CMS内容管理系统,基于asp.net建立,使用mssql进行存储数据.使用Umbraco,设计师能创造出有效的XHTML标记模板和 ...

  7. nginx的location配置

    http://blog.sina.com.cn/s/blog_97688f8e0100zws5.html http://blog.csdn.net/yanook/article/details/100 ...

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

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

  9. java--面向接口编程

    之前看的一本书的笔记,上周再看设计模式的时候,想到了这篇之前在看某本书时候的笔记. 面向接口编程很重要的一点就是接口回调,用接口声明的变量称作接口变量,属于引用型变量,可以存放实现该接口的类的实例的引 ...

  10. 在Windows 上的 Python

    在 Windows 上, 安装 Python 有两种选择. ActiveState 制作了一个 Windows 上的 Python 安装程序称为 ActivePython, 它包含了一个完整的 Pyt ...