bzoj2827千山鸟飞绝(Treap)
题目描述
输入
输出
样例输入
51 1 13 1 24 4 42 0 12 2 351 1 22 4 42 4 33 0 15 0 1
样例输出
34688
提示
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#define maxn 30005
#define maxm 300005
using namespace std;
inline int read()
{ char c=getchar();int x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=getchar();}while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();return x*y;
}
template<typename T>
inline T m_max(T x,T y){return x>y?x:y;}
int n,m,cnt,W[maxn],ans[maxn],ans2[maxn],las[maxn];
struct node
{ int x,y;node(int a=0,int b=0):x(a),y(b){}friend bool operator <(const node a,const node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
};
map<node,int>mp;
struct Treap
{ Treap *ch[2];int v,s,r,ma,ms;Treap(int x=0):v(x),s(1),ma(0),ms(0),r(rand()){ch[0]=ch[1]=NULL;}inline int sz(){return this?this->s:0;}inline void reval(int x,int y){ if(!this) return;this->ma=m_max(this->ma,x);this->ms=m_max(this->ms,y);ans[this->v]=m_max(ans[this->v],x);ans2[this->v]=m_max(ans2[this->v],y);}inline void mt(){if(!this) return; this->s=this->ch[0]->sz()+this->ch[1]->sz()+1;}inline void dn(){ if(!this) return;if(!this->ma&&!this->ms) return;this->ch[0]->reval(this->ma,this->ms);this->ch[1]->reval(this->ma,this->ms);this->ma=this->ms=0;}inline void rotate(Treap*& now,int d){ Treap* k=now->ch[d^1];now->dn();k->dn();now->ch[d^1]=k->ch[d];k->ch[d]=now;now->mt();k->mt();now=k;}inline void insert(Treap*& now,int x){ if(!now){now=new Treap(x);return;}now->dn();int d;if(W[x]<W[now->v]||(W[x]==W[now->v]&&x<now->v)) d=0;else d=1;insert(now->ch[d],x);if(now->ch[d]->r < now->r) rotate(now,d^1);now->mt();}inline void del(Treap*& now,int x){ now->dn();if(W[now->v]==W[x]&&now->v==x){ if(now->ch[0]&&now->ch[1]){ int d=now->ch[0]->r < now->ch[1]->r;rotate(now,d);del(now->ch[d],x);}else{ Treap* tmp=now;now=now->ch[0]?now->ch[0]:now->ch[1];delete tmp;//不能析构...}}else{ if(W[now->v]>W[x]||(W[now->v]==W[x]&&now->v>x)) del(now->ch[0],x);else del(now->ch[1],x);}if(now) now->mt();}inline int gmax(Treap* now){ if(!now->ch[1]) return W[now->v];return gmax(now->ch[1]);}
}*root[maxn+maxm];
int main()
{ n=read();node tmp;int x,y,z;for(int i=1;i<=n;++i){ W[i]=read();x=read();y=read();tmp=node(x,y);if(!mp.count(tmp)) mp[tmp]=++cnt;int now=mp[tmp];las[i]=now;if(root[now]) ans[i]=m_max(ans[i],root[now]->gmax(root[now])),root[now]->reval(W[i],0);root[now]->insert(root[now],i);root[now]->reval(0,root[now]->sz()-1);}m=read();for(int i=1;i<=m;++i){ x=read();y=read();z=read();tmp=node(y,z);if(!mp.count(tmp)) mp[tmp]=++cnt;int now=mp[tmp];root[las[x]]->del(root[las[x]],x);las[x]=now;if(root[now]) ans[x]=m_max(ans[x],root[now]->gmax(root[now])),root[now]->reval(W[x],0);root[now]->insert(root[now],x);root[now]->reval(0,root[now]->sz()-1);}for(int i=1;i<=n;++i) root[las[i]]->del(root[las[i]],i);for(int i=1;i<=n;++i) printf("%lld\n",(long long)ans[i]*ans2[i]);return 0;
}
bzoj2827千山鸟飞绝(Treap)相关推荐
- [POI2008] Poc (原名 Trians) Treap+Hash
这个题和千山鸟飞绝体现出了一种用平衡树解决动态集合问题,主要套路就是蜜汁标记. 这个题我一开始用替罪羊树搞了一下对了28个点,后来我换成了Treap一搞对了14个点,再后来发现被卡了Hash我竟然在自 ...
- 【Treap】bzoj1588-HNOI2002营业额统计
一.题目 Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司 ...
- 【bzoj2770】YY的Treap 权值线段树
题目描述 志向远大的YY小朋友在学完快速排序之后决定学习平衡树,左思右想再加上SY的教唆,YY决定学习Treap.友爱教教父SY如砍瓜切菜般教会了YY小朋友Treap(一种平衡树,通过对每个节点随机分 ...
- 2019 ICPC 南昌 K. Tree(树上启发式合并,平衡树 treap)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://nanti.jisuanke.com/t/42586 Problem 给定一 ...
- luogu P2596 [ZJOI2006]书架(平衡树、无旋treap(按排名分裂)一些更复杂的操作)
P2596 [ZJOI2006]书架 无旋treap可以维护一棵树的中序遍历结果.但是不支持通过编号来找节点.于是在无旋treap的基础上,我维护了每个节点的父亲,这样就可以求出一个节点是中序遍历中的 ...
- luogu P3391 【模板】文艺平衡树(FHQ - treap,懒惰标记)
整理的算法模板合集: ACM模板 我们把每个查询区间使用solit分裂成[1l−1][lr][r+1n][1~l-1][l~r][r+1~n][1 l−1][l r][r+1 n]三个区间. 再把[l ...
- 模板 - FHQ - treap 无旋平衡树
整理的算法模板合集: ACM模板 目录 FQH - treap 无旋平衡树 按权值分裂 按排名分裂 文艺平衡树 可持久化序列 FQH - treap 无旋平衡树 operator 1 : 插入一个数 ...
- 【数据结构】平衡树 - treap
treap = tree + heap 树堆(treap:让BST尽量随机) 动态维护一个有序序列 对于一个大根堆: 最大值:一直往右走 最小值:一直往左走 treap实现操作 set实现 ①插入 i ...
- BZOJ1112[POI2008]砖块Klo——非旋转treap
题目描述 N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖,放到另一柱.仓库无限大. 现在希望用最小次数的动作完成任 ...
- 三大平衡树(Treap + Splay + SBT)总结+模板
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #i ...
最新文章
- 标题: Debian 下 VirtualBox 的桥接、USB 设置 ── 迷你怎么做 [转自sir]
- 如何写一份优秀的Java程序员简历?
- boost::geometry::select_most_precise用法的测试程序
- 即将从TechReady5归来
- mysql no listenter_为什么mysql中用\G表示按列方式显示
- web应用服务器计算资源核算,浅谈网络计算与应用.doc
- Spark 学习(六) Spark 的线程安全和序列化问题
- Java异常处理-----finally
- c语言词法分析程序实验报告,词法分析器实验报告
- layui实际项目使用过程中遇到的兼容性问题
- 【Udacity项目】TMDb电影数据集探索分析
- 读书笔记2014第11本:历史上最伟大的10个方程
- 怎么可以快速解决网络劫持
- Hand Crafted 特征 PK 纯学习的特征提取方法
- 女工下班路上被3男子拖入黑巷 身中10多刀身亡
- 国外大数据初创公司巨额融资 国内公司初长成
- 2022 最新版java开发手册 黄山版
- Gitlab集成odoo单点登录
- 计算机图形学三(补充):重心坐标(barycentric coordinates)详解及其作用
- php nslookup,nslookup - 运维猫的个人空间 - OSCHINA - 中文开源技术交流社区
热门文章
- PAT测试 cccc竞赛
- Android 性能专项之 Memory Monitor 工具-memery
- 中国氨基酸表面活性剂市场前景展望与发展建议分析报告2022-2028年
- python 解压文件 重名_Python批量重命名压缩文件
- 机器人布里茨哪个皮肤好看_【图片】【全皮肤鉴赏系列】蒸汽机器人 布里茨【lol半价吧】_百度贴吧...
- 说说互联网公司中产品经理的几个指标
- expected primary-expression before ‘int‘
- OAuth2四种不同的标准模式
- html 隐藏tbody,隐藏的tbody
- 03.subview_and_superview