#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. MUI+html5的plus.webview页面传值在电脑浏览器上不可见

    使用plus.webview.currentWebview() 获得当前窗口的webview对象后,再使用document.write()输出显示webview的某个属性值,而plus.webview ...

  2. Nanodet模型部署(ncnn,openvino)/YOLOX部署(TensorRT)

    Nanodet模型部署(ncnn,openvino) nanodet官方代码库nanodet 1. nanodet模型部署在openvino上 step1: 参考链接 nanodet官方demo op ...

  3. ASP.NET MVC 处理管线模型

    MVC管道整体处理模型 1.在ASP.NET MVC处理管线中的第一站就是路由模块.当请求到达路由模块后,MVC框架就会根据Route Table中配置的路由模板来匹配当前请求以获得对应的contro ...

  4. .Net分表分库动态化处理

    介绍 本期主角:ShardingCore 一款ef-core下高性能.轻量级针对分表分库读写分离的解决方案,具有零依赖.零学习成本.零业务代码入侵 背景 最近有个小伙伴来问我,分表下他有一批数据,这个 ...

  5. 盘点微信小程序跨页面传值的若干方式

    直接给大家上干货 1.跳转页面传递参数 pageA.wxml <button type="primary" bindtap="jumpTo">点击跳 ...

  6. YAML在线验证

    推荐一个网站:YAML在线验证https://www.bejson.com/validators/yaml_editor/

  7. JavaScript中动态生成表格

    动态生成表格,首先需要输入并获取动态的数字,html中结构代码如下:行:<input type="text" id="row" value="5 ...

  8. javascript写淡入淡出效果的轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. vue.js中英文api

    全局配置 Vue.config is an object containing Vue's global configurations. You can modify its properties l ...

  10. linux配置svn

    1.安装 yum install subversion 2.测试安装是否成功: svnserve --version 3.创建目录并配置 建立版本库目录 mkdir -pv /data/svn/svn ...