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. neo4j----创建索引

    创建索引 create index on:Student(name) 删除索引 drop index on:Student(name) 创建唯一索引 create constraint on (s:T ...

  2. EF(EF Core)中的NotMappedAttribute(转载)

    NotMapped特性可以应用到EF实体类的属性中,Code-First默认的约定,是为所有带有get,和set属性选择器的属性创建数据列..NotManpped特性打破了这个约定,你可以使用NotM ...

  3. 20155211 网络攻防技术 Exp7 网络欺诈防范

    20155211 网络攻防技术 Exp7 网络欺诈防范 实践内容 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法.具体实践有 (1)简单应用SET工具建立冒名网站 (2)e ...

  4. 20155304《网络对抗》Exp7 网络欺诈技术防范

    20155304<网络对抗>Exp7 网络欺诈技术防范 实践内容 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法.具体实践有 (1)简单应用SET工具建立冒名网 ...

  5. 奔跑吧vivado

        上一节一上来就是Linux,不是炫耀我们的MiZ702能跑Linux,而是为了方便的把外设一次性测试完.大家都知道MiZ702精华在于FPGA与ARM的完美融合,就像太极一样阴阳调和--软中有 ...

  6. debian系统下改语言设置

    debian系统下改语言设置 安装debian 的时候选择了中文zh_CN_UTF-8,然后进系统后想换成en_US_UTF-8 可以使用一下命令选择:找到需要的语言 确定即可 dpkg-reconf ...

  7. 利用OVS+FLOODLIGHT,为数据表添加VLAN_ID和MPLS

    话不多说,直接上拓扑: 我这里是用主机h1 (10.0.0.1)ping 主机h2(10.0.0.2) 1.添加VLAN标签 v1: sudo ovs-ofctl add-flow m1-s1 in_ ...

  8. PowerBI开发 第十四篇:使用M公式添加列

    PowerBI的查询编辑器使用Power Query M公式语言来定义查询模型,它是一种富有表现力的数据糅合(Mashup)语言,一个M查询可以计算(Evalute)一个表达式,得到一个值. 对于开发 ...

  9. 利用JS实现一个简单的二级联动菜单

    前几天在看js的相关内容,所以就简单写了一个二级联动菜单.分享一下. <!DOCTYPE html> <html lang="en"> <head&g ...

  10. 软件工程第三次作业(One who wants to wear the crown, Bears the crown.)

    最大连续子数组和 题目 给定n个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的子段和的最大值.当所给的整数均为负数时定义子段和 ...