传送门

题目大意

分析

倒着跑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. UI多线程调用:线程间操作无效: 从不是创建控件"Form1"的线程访问它.

    有两种方式解决 1.在窗体构造函数中写Control.CheckForIllegalCrossThreadCalls =false;2.使用Invoke等委托函数. 问题原因是.net2.0以后拒绝多 ...

  2. #503. 「LibreOJ β Round」ZQC 的课堂 容斥原理+Treap

    题目: 题解: 比较容易发现 : \(x,y\) 的贡献是独立的. 所以可以分开考虑. 假设我们考虑 \(x\).向量在 \(x\) 方向的投影依次是 : \(\{a_1,a_2, ... ,a_n\ ...

  3. PHP使用curl请求https站点的常见错误及解决方案

    使用curl请求http站点和https站点最大的不同就是https站点有证书验证这一环节,如果证书验证不通过则无法发起请求,不管是请求什么类型的站点遇到问题时先把错误码打印出来看一下,打印错误码的代 ...

  4. php与JAVA的RSA加密互通

    Java 版本RSA 进行加密解密 在网上查询了好几天,最终找到解决方案,网络上都是通过Cipher.getInstance("RSA"); 而改成Cipher.getInstan ...

  5. (转)Android之Adapter用法总结

    1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(ListView,GridView)等地方都需要用到Adapter.如下图直 ...

  6. php-excel 与 laravel-excel

    php-excel: http://blog.csdn.net/evkj2013/article/details/65441170 php-excel中文手册(前端的jqury) http://www ...

  7. notifyDataSetChanged() 动态更新ListView

    有时候我们需要修改已经生成的列表,添加或者修改数据,notifyDataSetChanged()可以在修改适配器绑定的数组后,不用重新刷新Activity,通知Activity更新ListView.今 ...

  8. 【转】c# 判断指定文件是否存在

    private void button2_Click(object sender, EventArgs e) { if (File.Exists(@"E:\exists.txt") ...

  9. java代码反转toCharAT()的用法

    总结:反转注意for循环里面的变化 package clientFrame; //字符串反转 public class we { public static void main(String[] ar ...

  10. 1050 String Subtraction

    题意:给出两个字符串s1和s2,在s1中删去s2中含有的字符. 思路:注意,因为读入的字符串可能有空格,因此用C++的getline(cin,str).PAT系统迁移之后C语言中的gets()函数被禁 ...