传送门

题目大意

分析

倒着跑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. [BZOJ5290][HNOI2018]道路

    bzoj luogu sol 考场上普及\(dp\)都做不来,果然是思想僵化了. 设\(f[u][i][j]\)表示在\(u\)点,上方有\(i\)条未修复的公路和\(j\)条未修复的铁路的最小花费. ...

  2. 3625 codevs 士兵站队问题 中位数的妙用

    士兵站队问题 题目描述 Description 在一个划分成网格的操场上,n个士兵散乱地站在网格点上.网格点用整数坐标(x,y)表示.士兵们可以沿网格边往上.下.左.右移动一步,但在同一时刻任一网格点 ...

  3. CentOS虚拟机中安装VMWare Tools

    1.单击VMWare的[虚拟机]菜单,选择[安装VMWare Tools]命令 2.接着CentOS系统会自动挂载VMWare  Tools,并自动打开,如果没有打开可以自己去图形界面打开VMWare ...

  4. 阿里云ESC上面部署项目

    注意:我这里的服务器是Windows系统,后面会研究Linux下的命令 1.将javaWEB项目打包为war包 右击项目,先择“Export ” 2.通过“附件”->“远程连接桌面”,连接到服务 ...

  5. 使用pinyin4j汉字转pinyin

    引入maven依赖<dependencies> <dependency> <groupId>com.belerweb</groupId> <art ...

  6. CENTOS7配置静态IP后无法ping通外部网络的问题

    我今天想谈论的并不是如何配置静态IP,这样的话题已经有好多高手再谈. 我想谈的是为什么,我按照他们的教程无论如何也要发生各种问题,没办法连接外网的问题. 先给大家看我的最终版配置方案:我只修改了一个文 ...

  7. mysql权限验证流程

    mysql用户管理,逐级下查 mysql库的user表连接信息,全局权限db表记录用户对库的权限,对某个数据库的所有表的权限tables_priv 设置用户对表的权限columns_priv设置用户对 ...

  8. 【转】 Pro Android学习笔记(九一):了解Handler(5):组件生命

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 对于activity,消息是在OnCrea ...

  9. 【转】JMeter入门

    一.JMeter概述 JMeter就是一个测试工具,相比于LoadRunner等测试工具,此工具免费,且比较好用,但是前提当然是安装Java环境: JMeter可以做 (1)压力测试及性能测试: (2 ...

  10. elasticsearch pinyin 拼音分词器

    安装pinyin分词 地址:https://github.com/medcl/elasticsearch-analysis-pinyin PUT py_test { "index" ...