【线段树】hdu6183 Color it
题意:
维护一个数据结构,支持三种操作:
①在平面上(x,y)处添加一个颜色为c的点。
②询问平面上(1,y1)-(x,y2)范围内,有多少种不同颜色的点。
③清除平面上所有点。
颜色数量很少,对于每种颜色分别建立线段树,然后用线段树维护y坐标,对每个y坐标只存下来x坐标最小的点的x坐标,然后每次询问相当于问你[y1,y2]区间的最小值是否小于等于x。
卡常数,必须用动态开点线段树,并且在询问的时候进行剪枝(在区间内如果遇到了满足条件的子区间,直接返回true,不继续检查其他子区间了)。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=2147483647;
int root[55],lc[4000005],rc[4000005],v[4000005];
int tot;
void newnode(int &rt){
rt=++tot;
lc[rt]=rc[rt]=0;
v[rt]=INF;
}
void update(int p,int x,int &rt,int l,int r){
if(!rt){
newnode(rt);
}
if(l==r){
v[rt]=min(v[rt],x);
return;
}
int m=(l+r>>1);
if(p<=m){
update(p,x,lc[rt],l,m);
}
else{
update(p,x,rc[rt],m+1,r);
}
v[rt]=min(v[lc[rt]],v[rc[rt]]);
}
bool query(int x,int ql,int qr,int rt,int l,int r)
{
if(!rt){
return 0;
}
if(ql<=l && r<=qr){
if(v[rt]<=x){
return 1;
}
return 0;
}
int m=(l+r>>1);
if(ql<=m){
if(query(x,ql,qr,lc[rt],l,m)){
return 1;
}
}
if(m<qr){
if(query(x,ql,qr,rc[rt],m+1,r)){
return 1;
}
}
return 0;
}
int main()
{
// freopen("b.in","r",stdin);
int op,x,y,z;
v[0]=INF;
while(1){
scanf("%d",&op);
if(op==3){
break;
}
if(op==0){
memset(root,0,sizeof(root));
tot=0;
}
else if(op==1){
scanf("%d%d%d",&x,&y,&z);
update(y,x,root[z],1,1000000);
}
else if(op==2){
scanf("%d%d%d",&x,&y,&z);
int ans=0;
for(int i=0;i<=50;++i){
ans+=query(x,y,z,root[i],1,1000000);
}
printf("%d\n",ans);
}
}
return 0;
}
【线段树】hdu6183 Color it的更多相关文章
- Count Colour_poj2777(线段树+位)
POJ 2777 Count Color (线段树) Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- 2018.07.08 hdu6183 Color it(线段树)
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...
- hdu6183 Color it 线段树动态开点+查询减枝
题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形 ...
- HDU6183 Color it (线段树动态开点)
题意: 一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色 思路: 建立50颗线段树,对每个颜色的线段树,维护每个y坐标上 ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- POJ 2777 Count Color(线段树之成段更新)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...
随机推荐
- SQL Server Delete Duplicate Rows
There can be two types of duplication of rows in a table 1. Entire row getting duplicated because th ...
- python初步学习-pycharm使用
Pycharm简介 PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成. ...
- Eudyptula Challenge
http://www.eudyptula-challenge.org/ The Eudyptula Challenge What is it? The Eudyptula Challenge is a ...
- java===java基础学习(7)---用户自定义类
package testbotoo; import java.util.*; public class EmployeeTest { public static void main(String[] ...
- HDU 5117 Fluorescent
题目链接:HDU-5117 题意为有n盏灯,m个开关,每个开关控制着\( k_{i} \)灯.X为最后亮着的灯的个数,要求出\( E(X^{3} ) * 2^{M} mod (10^9 + 7) \) ...
- 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ...
- caffe solver.prototxt 生成
from caffe.proto import caffe_pb2 s = caffe_pb2.SolverParameter() path='/home/xxx/data/' solver_file ...
- VM虚拟机,Linux系统安装tools过程遇到 what is the location of the “ifconfig” program
安装步骤: 复制到/mnt 解压文件 tar -zxvf VMwareTools-10.1.6-5214329.tar.gz 进入减压文件夹后安装 ./vmware-install.pl ... 一直 ...
- POJ-2398
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4243 Accepted: 2517 Descr ...
- Mybatis学习—XML映射文件
总结自 Mybatis官方中文文档 Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同 ...