Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The specific format of these operations is as follows.

00 : clear all the points.

11 xx yy cc : add a point which color is cc at point (x,y)(x,y).

22 xx y1y1 y2y2 : count how many different colors in the square (1,y1)(1,y1) and (x,y2)(x,y2). That is to say, if there is a point (a,b)(a,b) colored cc, that 1≤a≤x1≤a≤x and y1≤b≤y2y1≤b≤y2, then the color cc should be counted.

33 : exit. 

InputThe input contains many lines.

Each line contains a operation. It may be '0', '1 x y c' ( 1≤x,y≤106,0≤c≤501≤x,y≤106,0≤c≤50), '2 x y1 y2' (1≤x,y1,y2≤1061≤x,y1,y2≤106 ) or '3'.

x,y,c,y1,y2x,y,c,y1,y2 are all integers.

Assume the last operation is 3 and it appears only once.

There are at most 150000150000 continuous operations of operation 1 and operation 2.

There are at most 1010 operation 0.

OutputFor each operation 2, output an integer means the answer . 
Sample Input

0
1 1000000 1000000 50
1 1000000 999999 0
1 1000000 999999 0
1 1000000 1000000 49
2 1000000 1000000 1000000
2 1000000 1 1000000
0
1 1 1 1
2 1 1 2
1 1 2 2
2 1 1 2
1 2 2 2
2 1 1 2
1 2 1 3
2 2 1 2
2 10 1 2
2 10 2 2
0
1 1 1 1
2 1 1 1
1 1 2 1
2 1 1 2
1 2 2 1
2 1 1 2
1 2 1 1
2 2 1 2
2 10 1 2
2 10 2 2
3

Sample Output

2
3
1
2
2
3
3
1
1
1
1
1
1
1 思路:
有50种颜色,对每一种颜色建一颗线段树维护,动态开点。
第一种操作:使点(x,y)的颜色变为c
第二种:询问(1,y1),(x,y2)两点间的颜色种类数量
我们可以以y轴建线段树,横坐标为值,那么要确定两点之前是否存在某种颜色,只要询问下每个颜色在y1,y2之间最小的值(也就是横坐标).判断下最小值是否小于第二种操作给出的x,如果小于的话就代表两点间存在这种颜色。 实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mid int m = (l + r) >> 1
const int M = 1e6+;
int n = 1e6,flag=;
int sum[M],ne=,ls[M],rs[M],rt[]; void update(int &k,int l,int r,int p,int num){
if(!k){ //如果当前区间未拓展,拓展并赋值
k = ++ne;
sum[k] = num;
}
sum[k] = min(sum[k],num);//当前区间有值,更新下最小值
if(l == r)
return ;
mid;
if(p <= m) update(ls[k],l,m,p,num);
else update(rs[k],m+,r,p,num);
} void query(int k,int L,int R,int l,int r,int up){
if(!k||flag) return ;
if(L <= l&&R >= r){
if(sum[k]<=up)
flag = ;
return;
}
mid;
if(L <= m) query(ls[k],L,R,l,m,up);
if(R > m) query(rs[k],L,R,m+,r,up);
return ;
} void init(){
memset(rt,,sizeof(rt));
memset(sum,,sizeof(sum));
memset(ls,,sizeof(ls));
memset(rs,,sizeof(rs));
ne = ;
}
int main()
{
int op,x,y,z;
while(~scanf("%d",&op)){
if(op == )
init();
else if(op == ){
scanf("%d%d%d",&x,&y,&z);
update(rt[z],,n,y,x);
}
else if(op == ){
scanf("%d%d%d",&x,&y,&z);
int ans = ;
for(int i = ;i <= ;i ++){
flag = ;
query(rt[i],y,z,,n,x);
if(flag) ans++;
}
printf("%d\n",ans);
}
else return ;
}
return ;
}

hdu 6183 Color it (线段树 动态开点)的更多相关文章

  1. HDU - 6183 暴力,线段树动态开点,cdq分治

    B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...

  2. hdu6183 Color it 线段树动态开点+查询减枝

    题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形 ...

  3. HDU 6183 Color it 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...

  4. HDU6183 Color it (线段树动态开点)

    题意: 一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色 思路: 建立50颗线段树,对每个颜色的线段树,维护每个y坐标上 ...

  5. BZOJ_4636_蒟蒻的数列_线段树+动态开点

    BZOJ_4636_蒟蒻的数列_线段树+动态开点 Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将 ...

  6. P3939 数颜色 线段树动态开点

    P3939 数颜色 线段树动态开点 luogu P3939 水.直接对每种颜色开个权值线段树即可,注意动态开点. #include <cstdio> #include <algori ...

  7. 洛谷P3313 [SDOI2014]旅行 题解 树链剖分+线段树动态开点

    题目链接:https://www.luogu.org/problem/P3313 这道题目就是树链剖分+线段树动态开点. 然后做这道题目之前我们先来看一道不考虑树链剖分之后完全相同的线段树动态开点的题 ...

  8. codedecision P1113 同颜色询问 题解 线段树动态开点

    题目描述:https://www.cnblogs.com/problems/p/11789930.html 题目链接:http://codedecision.com/problem/1113 这道题目 ...

  9. HDU - 6183:Color it (线段树&动态开点||CDQ分治)

    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...

随机推荐

  1. iOS11 Xcode 9 按住command 单击 恢复到从前(直接跳转到定义)

    iOS11 Xcode 9  按住command 单击 恢复到从前(直接跳转到定义)   2017年9月20日,苹果如期推送 Xcode 9 和 iOS 11的更新. Xcode 9正式版与之前bet ...

  2. Docker的Mysql数据库:把数据存储在本地目录

    Docker mysql 把数据存储在本地目录,很简单,只需要映射本地目录到容器即可 1.加上-v参数 $ docker run -d -e MYSQL_ROOT_PASSWORD=admin --n ...

  3. Android 下拉刷新上拉加载PullToRefresh

    https://github.com/823546371/PullToRefresh http://www.jianshu.com/p/0f5d0991efdc

  4. 遍历目录删除指定MD5值的文件

    工作需要实现一个查找出指定目录下md5值与excel表格中md5值相同的文件然后删掉的功能.我是这样做的:首先遍历指定目录,计算该目录下所有文件的md5值,以文件路径为key,md5值为value保存 ...

  5. 20155331 Exp3 免杀原理与实践

    20155331 Exp3 免杀原理与实践 基础问题回答 杀软是如何检测出恶意代码的? 1.基于特征码的检测,2.启发式恶意软件检测,3.基于行为的恶意软件检测. 免杀是做什么? 让病毒不被杀毒软件杀 ...

  6. Vue 项目集合

    饿了么安全应急响应中心 饿了么招聘 饿了么前端 · GitHub 稀土掘金 异乡好居 明星垂搜 广州建管 基于Vue.js的数据统计系统(一) 基于Vue.js的数据统计系统(二) 基于Vue.js的 ...

  7. ActiveMQ 的安装与使用(springboot版本)

    一.安装 上官网下载tar包 http://activemq.apache.org/ tar -zxvf 后进入bin/linux-86-64 ./activimq start 启动 二.使用 pom ...

  8. MFC CHotKeyCtrl控件

    知识点: CHotKeyCtrl控件 获取热键数据 注册热键 响应热键事件 一.CHotKeyCtrl控件 void SetHotKey( WORD wVirtualKeyCode, WORD wMo ...

  9. 在sourceinsight中添加快速注释 Ctrl+/

    1.搜索文件:utils.em(C:\Program Files (x86)\Source Insight 3)2.用sourceinsight打开文件:utils.em3.在文件末尾添加下面代码 m ...

  10. Kubernetes学习之路(二十二)之Pod资源调度

    目录 Pod资源调度 1.常用的预选策略 2.优选函数 3.节点亲和调度 3.1.节点硬亲和性 3.2.节点软亲和性 4.Pod资源亲和调度 4.1.Pod硬亲和度 4.2.Pod软亲和度 4.3.P ...