#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl #else #define D_e_Line ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 50007; struct node{
int l,r,fa,id;
int val,pri;
bool operator < (const node &com)const{
return val < com.val;
}
}t[N],ans[N]; inline void Insert(int rt){
int tmp;
for(tmp = rt - 1; t[tmp].pri > t[rt].pri; tmp = t[tmp].fa);
t[rt].l = t[tmp].r;
t[t[tmp].r].fa = rt;
t[rt].fa = tmp;
t[tmp].r = rt;
} int vis[30007];
int main(){
int n;
while(scanf("%d", &n) != EOF){
Fill(vis, false);
int flag = true;
R(i,0,n){
t[i].l = t[i].r = t[i].fa = 0;
t[i].w = -0x7fffffff;
} R(i,1,n){
scanf("%d%d", &t[i].val, &t[i].w);
t[i].id = i;
if(vis[t[i].val])
flag = false;
else
vis[t[i].val] = true;
}
if(!flag){
printf("NO\n");
continue;
}
printf("YES\n"); sort(t + 1, t + n + 1); R(i,1,n) Insert(i); R(i,1,n){
if(!t[i].l)
ans[t[i].id].l = 0;
else
ans[t[i].id].l = t[t[i].l].id;
if(!t[i].r)
ans[t[i].id].r = 0;
else
ans[t[i].id].r = t[t[i].r].id;
if(!t[i].fa)
ans[t[i].id].fa = 0;
else
ans[t[i].id].fa = t[t[i].fa].id;
} R(i,1,n)
printf("%d %d %d\n", ans[i].fa, ans[i].l, ans[i].r);
} return 0;
}

POJ2201 Cartesian Tree (cartesian tree)的更多相关文章

  1. ZOJ 3201 Tree of Tree

    树形DP.... Tree of Tree Time Limit: 1 Second      Memory Limit: 32768 KB You're given a tree with weig ...

  2. LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]

    Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...

  3. B-tree/B+tree/B*tree [转]

    (原文出处:http://blog.csdn.net/hbhhww/article/details/8206846) B~树 1.前言: 动态查找树主要有:二叉查找树(Binary Search Tr ...

  4. leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree

    leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree 1 题目 Binary Search Tre ...

  5. [BZOJ3080]Minimum Variance Spanning Tree/[BZOJ3754]Tree之最小方差树

    [BZOJ3080]Minimum Variance Spanning Tree/[BZOJ3754]Tree之最小方差树 题目大意: 给定一个\(n(n\le50)\)个点,\(m(m\le1000 ...

  6. easyui tree扩展tree方法获取目标节点的一级子节点

    Easyui tree扩展tree方法获取目标节点的一级子节点 /* 只返回目标节点的第一级子节点,具体的用法和getChildren方法是一样的 */ $.extend($.fn.tree.meth ...

  7. Tree - Decision Tree with sklearn source code

    After talking about Information theory, now let's come to one of its application - Decision Tree! No ...

  8. Binary Indexed Tree (Fenwick Tree)

    Binary Indexed Tree 主要是为了存储数组前缀或或后缀和,以便计算任意一段的和.其优势在于可以常数时间处理更新(如果不需要更新直接用一个数组存储所有前缀/后缀和即可).空间复杂度O(n ...

  9. POJ1741 Tree + BZOJ1468 Tree 【点分治】

    POJ1741 Tree + BZOJ1468 Tree Description Give a tree with n vertices,each edge has a length(positive ...

  10. B-tree & B+tree & B*Tree 结构浅析——转

    转自http://www.cnblogs.com/coder2012/p/3330311.html http://blog.sina.com.cn/s/blog_6776884e0100ohvr.ht ...

随机推荐

  1. 一文学完Linux Shell编程,比书都好懂

    一. Shell 编程 1. 简介 Shell 是一个用 C 语言编写的程序,通过 Shell 用户可以访问操作系统内核服务. Shell 既是一种命令语言,又是一种程序设计语言. Shell scr ...

  2. 分布式任务调度ScheduleMaster

    1.什么是ScheduleMaster ScheduleMaster是分布式任务调度系统.简称:集中任务调度系统,最简单的理解ScheduleMaster,就是对不同的系统里面的调度任务做统一管理的框 ...

  3. 《HALCON数字图像处理》第五章笔记

    目录 第五章 图像运算 图像的代数运算 加法运算 图像减法 图像乘法 图像除法 图像逻辑运算(位操作) 图像的几何变换 图像几何变换的一般表达式 仿射变换 投影变换 灰度插值 图像校正 我在Gitee ...

  4. 使用pip安装库或执行pip命令时报错解决方案

    初次安装pip后执行安装升级一般不会有问题,但是国外的镜像源下载升级由于网速过慢会进行报错,提示需要升级 pip 或者下载速度很慢最后直接报了错如下图: 这个时候只需要修改镜像源即可,建议修改为永久镜 ...

  5. 看看CabloyJS是如何实现编辑页面脏标记的

    应用场景 我们在使用Word.Excel时,当修改了内容之后在标题栏会显示脏标记,从而可以明确的告知用户内容有变动.此外,如果在没有保存的情况下关闭窗口,系统会弹出提示框,让用户选择是否放弃修改 那么 ...

  6. Typora配置阿里云图床

    一.Typora安装PicGo 更新typora到最新版,打开文件-->偏好设置-->图像-->上传服务选择PicGo-Core-->下载或更新   二.注册并配置阿里云 1. ...

  7. SAP APO-供应网络计划

    供应网络计划整合了供应链中的所有流程-采购,制造和分销. 供应网络计划可以优化采购和生产,缩短订单完成时间,并改善客户服务. 供应网络计划与高级计划和优化的其他过程紧密集成,以开发用于购买,制造和分配 ...

  8. Tensorflow2 深度学习十必知

    博主根据自身多年的深度学习算法研发经验,整理分享以下十条必知. 含参考资料链接,部分附上相关代码实现. 独乐乐不如众乐乐,希望对各位看客有所帮助. 待回头有时间再展开细节说一说深度学习里的那些道道. ...

  9. NC16649 [NOIP2005]校门外的树

    NC16649 [NOIP2005]校门外的树 题目 题目描述 某校大门外长度为 \(L\) 的马路上有一排树,每两棵相邻的树之间的间隔都是 \(1\) 米.我们可以把马路看成一个数轴,马路的一端在数 ...

  10. Spring框架系列(13) - SpringMVC实现原理之DispatcherServlet的初始化过程

    前文我们有了IOC的源码基础以及SpringMVC的基础,我们便可以进一步深入理解SpringMVC主要实现原理,包含DispatcherServlet的初始化过程和DispatcherServlet ...