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 显然, ...
随机推荐
- hdu 1376 Octal Fractions
刚开始做这题时,用的是0.75[8]=(7/8+5/64)[10]这个,但是总是WA…………无语了…… 后来看别人的解题报告,知道了另外一个就是0.75[8]=((5/8+7)/8)[10],从低位向 ...
- Android 注意在finish Activity之后也要停止正在运行的请求
如果在一个Activity里面启动了网络请求,而在这个网络请求还没返回结果的时候,如果Activity被结束了,则我们需要写如下代码作为防守: @Override public void onPost ...
- spring webservice 搭建出现的异常处理。异常: NAMESPACE_ERR: An attempt is made to create or change an object in a way whi
异常:NAMESPACE_ERR: An attempt is made to create or change an object in a way whi---- 这是我自己写客户端调用webse ...
- lintcode :sort letters by case字符大小写排序
题目 字符大小写排序 给定一个只包含字母的字符串,按照先小写字母后大写字母的顺序进行排序. 您在真实的面试中是否遇到过这个题? Yes 样例 给出"abAcD",一个可能的答案为& ...
- lintcode 中等题: Implement Trie
题目 Implement Trie Implement a trie with insert, search, and startsWith methods. 样例 注意 You may assu ...
- iOS开发--使用NSMutableAttributedString 实现富文本
在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...
- Photoshop CS4序列号过期的问题
1)在网络上搜寻一些PS CS4序列号: 如1330-1221-6824-4838-0308-6823,1330-1283-7461-4574-7002-2504,1330-1795-2880-537 ...
- KMP算法的C++实现
这个问题阮一峰老师讲的很清楚,链接 这里我只贴一下我的C++实现代码: #include <iostream> #include <cstring> #include < ...
- 最受欢迎的5款PHP框架记录,我居然一个不知道。。。
1. CodeIgniter Framework CodeIgniter 是目前使用最广泛的 PHP 框架.CodeIgniter 是一个简单快速的PHP MVC 框架.EllisLab 的工作人员发 ...
- oracle db shutdown immediate–multi Instance
[oracle@redhat4 ~]$ sqlplus / as sysdba@orcl SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 21 ...