hdu6183(线段树动态开点)
来源:互联网 发布:源生活网络超市 编辑:程序博客网 时间:2024/05/29 17:41
链接:点击打开链接
题意:有三种操作,分别为:
0 清除矩阵中所有颜色
1 x y c 在(x,y)点涂上c颜色
2 x y1 y2 询问左上角为(1,y1),右上角为(x,y2)的矩阵中含有的颜色种数
代码:
#include <stack>#include <string>#include <vector>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int siz=1000005;int id=0;int rt[105],ll[siz],rr[siz],val[siz];void build(int &s,int p,int L,int R,int x){ if(s==0){ //主要就是动态开点,需要时再建立节点 s=(++id); //并不会建一颗完整的线段树 val[s]=x; //剩下的跟静态建线段树是一样的 } if(val[s]>x) val[s]=x; if(L==R) return; int m=(L+R)>>1; if(p<=m) build(ll[s],p,L,m,x); else build(rr[s],p,m+1,R,x);}void query(int p,int L,int R,int l,int r,int x,int &pos){ if(l<=L&&R<=r){ //查询时最好也不要遍历整颗树 if(val[p]<=x) //已经小于就不再继续遍历 pos=1; return; } if(pos) return; int m=(L+R)>>1; if(l<=m&&ll[p]!=0) query(ll[p],L,m,l,r,x,pos); if(r>m&&rr[p]!=0) query(rr[p],m+1,R,l,r,x,pos); //整体思路就是建50颗线段树} //按y轴建树,单点更新,求区间最小的x值int main(){ //rt[i]表示i颜色线段树的根节点 int i,c,x,y1,y2,op,ans,pos; //ll[i]表示编号i节点的左儿子 memset(rt,0,sizeof(rt)); //rr[i]表示编号i节点的右儿子 memset(ll,0,sizeof(ll)); memset(rr,0,sizeof(rr)); while(scanf("%d",&op)&&op!=3){ if(op==0){ for(i=0;i<=50;i++) rt[i]=0; for(i=0;i<=id;i++) ll[i]=rr[i]=0; id=0; } else if(op==1){ scanf("%d%d%d",&x,&y1,&c); build(rt[c],y1,1,1000000,x); } else if(op==2){ scanf("%d%d%d",&x,&y1,&y2); ans=0; for(i=0;i<=50;i++){ pos=0; query(rt[i],1,1000000,y1,y2,x,pos); if(pos==1) ans++; } printf("%d\n",ans); } } return 0;}
阅读全文
0 0
- hdu6183(线段树动态开点)
- HDU6183 Color it(线段树 动态开点)
- HDU6183(线段树)
- 动态建线段树,hdu6183,参考杰少的博客
- 【HDU6183】Color it(线段树)
- HDU6183 cdq分治+线段树
- HDU6183 Color it【线段树】
- ***hdu6183
- [BZOJ3531][SDOI2014]旅行(链剖+线段树动态开点)
- 【bzoj3531】[Sdoi2014]旅行 动态开点的线段树
- BZOJ 3531 (树链剖分,线段树动态开点)
- bzoj3531 [Sdoi2014]旅行 【树链剖分+线段树动态开点】
- NOIP 2017 列队 (线段树动态开点)
- hdu 4918 Query on the subtree (动态点分治+动态开点+线段树)
- 【题】【线段树(动态开点&负点)】NKOJ 1922 第K小数
- 【树状数组+线段树动态开点】BZOJ3295(Cqoi2011)[动态逆序对]题解
- Educational Codeforces Round 20 G. Periodic RMQ Problem(线段树动态开点)
- [NOIP2016] 天天爱跑步 (LCA+线段树(动态开点)+差分+dfs序)
- Drawerlayout侧滑菜单
- Android异步消息处理机制完全解析,带你从源码的角度彻底理解
- 精选20道Java多线程面试题并有答案! 互联网IT技术 2017-10-14 00:02 1. 多线程使用的优缺点? 优点: (1)多线程技术使程序的响应速度更快 (2)当前没有进行处理的任务
- 第一章课后习题
- 数据库探索之旅——数据类型
- hdu6183(线段树动态开点)
- 利用ECharts3来实现ECharts2实例中的模拟迁徙效果,即背景地图为百度地图。 标签: ECharts3Echarts2模拟迁徙百度地图引入 2016-10-24 16:21 10065人阅
- 为什么朴素贝叶斯如此“朴素”?
- C语言 使用计算两个时间的差,使用结构体
- 矩阵中的路径java实现
- android开源
- VC对xml文件的读写
- 字符串的冒泡排序
- 1084. Broken Keyboard (20)