传送门

题目大意

分析

倒着跑LIS表示以i为开头的LIS,于是对于删除可以暴力重算前10棵树。而对于种树,因为高度不超过10且高度两两不同,所以暴力重算比它矮的10棵树即可。对于需要重算的点,将其从线段树中删掉然后重算即可。我们要维护一个关于x轴的线段树和一个关于y轴的线段树,重算下边的点需要使用关于x轴的线段树,而重算左边的点需要另一个线段树,注意在修改一个点的时候应该将它在两课线段树中的信息同时修改

我们可以x轴y轴各开一个堆,这样就可以每次取出最小的几个进行操作了

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,dx[],dy[],pl[],h[],Ans,N;
bool is[];
priority_queue<pair<int,int> >x,y;
stack<pair<int,int> >xa,ya;
inline void upx(int le,int ri,int wh,int pl,int k){
if(le==ri){dx[wh]=k;return;}
int mid=(le+ri)>>;
if(mid>=pl)upx(le,mid,wh<<,pl,k);
else upx(mid+,ri,wh<<|,pl,k);
dx[wh]=max(dx[wh<<],dx[wh<<|]);
}
inline void upy(int le,int ri,int wh,int pl,int k){
if(le==ri){dy[wh]=k;return;}
int mid=(le+ri)>>;
if(mid>=pl)upy(le,mid,wh<<,pl,k);
else upy(mid+,ri,wh<<|,pl,k);
dy[wh]=max(dy[wh<<],dy[wh<<|]);
}
inline int qx(int le,int ri,int wh,int xx,int yy){
if(le>=xx&&ri<=yy)return dx[wh];
int mid=(le+ri)>>,res=;
if(mid>=xx)res=max(res,qx(le,mid,wh<<,xx,yy));
if(mid<yy)res=max(res,qx(mid+,ri,wh<<|,xx,yy));
return res;
}
inline int qy(int le,int ri,int wh,int xx,int yy){
if(le>=xx&&ri<=yy)return dy[wh];
int mid=(le+ri)>>,res=;
if(mid>=xx)res=max(res,qy(le,mid,wh<<,xx,yy));
if(mid<yy)res=max(res,qy(mid+,ri,wh<<|,xx,yy));
return res;
}
int main(){
int i,j,k,X,Y;
scanf("%d%d",&n,&m);
N=m+;
for(i=;i<=m;i++){
scanf("%d",&k);
if(k==){
//h小,维护高度,Y
scanf("%d%d",&pl[i],&h[i]);
x.push(make_pair(-pl[i],i));
h[i]+=m-i;
while(!y.empty()){
if(-y.top().first<=h[i]){
if(!is[pl[y.top().second]])ya.push(y.top());
upy(,n,,pl[y.top().second],);
y.pop();
}else break;
}
ya.push(make_pair(-h[i],i));
while(!ya.empty()){
y.push(ya.top()),ya.pop();
Y=qy(,n,,pl[y.top().second]+,n)+;
upx(,N,,-y.top().first,Y);
upy(,n,,pl[y.top().second],Y);
}
Ans=dy[];
}else {
scanf("%d",&X);
while(X){
X--;
if(X){
xa.push(x.top());
x.pop();
upx(,N,,h[xa.top().second],);
}else break;
}
upy(,n,,-x.top().first,);
upx(,N,,h[x.top().second],);
is[-x.top().first]=;
x.pop();
while(!xa.empty()){
x.push(xa.top()),xa.pop();
int Y=qx(,N,,h[x.top().second]+,N)+;
upy(,n,,-x.top().first,Y);
upx(,N,,h[x.top().second],Y);
}
Ans=dx[];
}
printf("%d\n",Ans);
}
return ;
}

264E Roadside Trees的更多相关文章

  1. Codeforces.264E.Roadside Trees(线段树 DP LIS)

    题目链接 \(Description\) \(Solution\) 还是看代码好理解吧. 为了方便,我们将x坐标左右反转,再将所有高度取反,这样依然是维护从左到右的LIS,但是每次是在右边删除元素. ...

  2. Codeforces Round #162 (Div. 2)

    A. Colorful Stones (Simplified Edition) 模拟. B. Roadside Trees (Simplified Edition) 每次转移时,只需要爬到\(min( ...

  3. Codeforces Round #162 (Div. 2) A~D 题解

    A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 mega ...

  4. Noip 训练指南

    目录 Noip 训练指南 图论 数据结构 位运算 期望 题解 Noip 训练指南 目前完成 \(4 / 72\) 图论 [ ] 跳楼机 [ ] 墨墨的等式 [ ] 最优贸易 [ ] 泥泞的道路 [ ] ...

  5. [C#] C# 知识回顾 - 表达式树 Expression Trees

    C# 知识回顾 - 表达式树 Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译表达式树 执行表达式树 修改表达 ...

  6. hdu2848 Visible Trees (容斥原理)

    题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...

  7. [LeetCode] Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  8. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  9. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

随机推荐

  1. Hibernate中 一 二级缓存及查询缓存(1)

    最近趁有空学习了一下Hibernate的缓存,其包括一级缓存,二级缓存和查询缓存(有些是参照网络资源的): 一.一级缓存     一级缓存的生命周期和session的生命周期一致,当前sessioin ...

  2. 学习动态性能表(3)--v$sql&v$sql_plan

    学习动态性能表 第三篇-(1)-v$sq 2007.5.25 V$SQL中存储具体的SQL语句. 一条语句可以映射多个cursor,因为对象所指的cursor可以有不同用户(如例1).如果有多个cur ...

  3. ORA-28595: Extproc 代理: DLL 路径无效解决办法

    报错信息: ORA-28595: Extproc 代理: DLL 路径无效 ORA-06512: 在 "SDE.ST_GEOMETRY_SHAPELIB_PKG", line 70 ...

  4. 为什么我的 FastAdmin 慢?

    为什么我的 FastAdmin 慢? 排查流程 询问 demo.fastadmin.net 是否慢,官方 demo 安装了 80% 的插件. 开发时一般都是打开 debug 配置,上线要把 debug ...

  5. Java问题:中间件是什么

    和朋友聊天时被问到中间件是什么?一时有点语赛,感觉熟悉这个概念,但又完全不知道如何清楚的向别人讲这些. 网络上搜了一下,也没找到让自己很认可的说法,有的说非业务的技术类组件,是操作系统之上和业务逻辑之 ...

  6. Raid 技术简介

    独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列,简称硬盘阵列.其基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵 ...

  7. CF 1088(A , B , C , D)——思路

    http://codeforces.com/contest/1088 A:Ehab and another construction problem 输出 2 和 n(偶数的话)或者 2 和 n-1( ...

  8. npm包的发布

    假设该待发布包在你本地的项目为 project1 包的本地安装测试 在发布之前往往希望在本地进行安装测试.那么需要一个其他的项目来本地安装待发布项目. 假设该其他项目为project2.假设proje ...

  9. further occurrences of HTTP header parsing errors will be logged at DEBUG level.

    1.   获取参数Json的值为null String json=request.getParameter("Json"); 首先检查是否有下面的东东, 信息: Error par ...

  10. Memcached数据存储方式

    1. memcached的数据存储方式被称为Slab Allocator,其基本方式是: ①:先把内存分成很多Slab,这个大小是预先规定好的,已解决内存碎片的问题.分配给Slab的内存空间被称为Pa ...