264E Roadside Trees
题目大意

分析
倒着跑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的更多相关文章
- Codeforces.264E.Roadside Trees(线段树 DP LIS)
题目链接 \(Description\) \(Solution\) 还是看代码好理解吧. 为了方便,我们将x坐标左右反转,再将所有高度取反,这样依然是维护从左到右的LIS,但是每次是在右边删除元素. ...
- Codeforces Round #162 (Div. 2)
A. Colorful Stones (Simplified Edition) 模拟. B. Roadside Trees (Simplified Edition) 每次转移时,只需要爬到\(min( ...
- Codeforces Round #162 (Div. 2) A~D 题解
A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 mega ...
- Noip 训练指南
目录 Noip 训练指南 图论 数据结构 位运算 期望 题解 Noip 训练指南 目前完成 \(4 / 72\) 图论 [ ] 跳楼机 [ ] 墨墨的等式 [ ] 最优贸易 [ ] 泥泞的道路 [ ] ...
- [C#] C# 知识回顾 - 表达式树 Expression Trees
C# 知识回顾 - 表达式树 Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译表达式树 执行表达式树 修改表达 ...
- hdu2848 Visible Trees (容斥原理)
题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...
- [LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
随机推荐
- Quartz 2D编程指南(1) - 概览
Quartz 2D编程指南是论坛会员德鲁伊翻译的国外的Quartz 2D一系列学习资料,供大家参考 Quartz 2D是一个二维图形绘制引擎,支持iOS环境和Mac OS X环境.我们可以使用Quar ...
- LeetCode Design TinyURL
原题链接在这里:https://leetcode.com/problems/design-tinyurl/description/ 题目: How would you design a URL sho ...
- Windows 7 扩展玻璃效果(Aero Glass)
转自:http://www.cnblogs.com/gnielee/archive/2010/10/04/windows7-extend-aero-glass.html Windows 7 操作系统默 ...
- matlab与modelsim中的文件操作函数
matlab中 fscanf和fpintf是一对,用fprintf写的必须用fscanf来读. fread和fwrite是一对,用fwrite写的必须用fread来读. 同样的数据,使用fprintf ...
- 七、Jmeter + ant + jenkins轻量级接口自动化测试
七.Jmeter + ant + jenkins轻量级接口自动化测试 杀猪不用牛刀,工具没有牛逼高大尚之分,每个工具都有存在的理由:关键是看会不会用,怎么用,有没有用在合适的地方. 需要安装的工具: ...
- 题目1534:数组中第K小的数字 ——二分
http://ac.jobdu.com/problem.php?pid=1534 给定两个整型数组A和B.我们将A和B中的元素两两相加可以得到数组C.譬如A为[1,2],B为[3,4].那么由A和B中 ...
- flume采集log4j日志到kafka
简单测试项目: 1.新建Java项目结构如下: 测试类FlumeTest代码如下: package com.demo.flume; import org.apache.log4j.Logger; pu ...
- composer的安装和使用 学习日志
如果你做为一个phper,没有用过composer,那你真的不是一个合格的开发者.那么就来记录一下composer的学习日志 下面分享几个学习源头: composer中文网站:https://www. ...
- 南阳OJ 1170 最大的数
最大的数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 小明和小红在打赌说自己数学学的好,于是小花就给他们出题了,考考他们谁NB,题目是这样的给你N个数 在这n个数 ...
- POJ3020(最小边覆盖)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8924 Accepted: 4428 ...