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. 第11章 GPIO输出—使用固件库点亮LED

    第11章     GPIO输出—使用固件库点亮LED 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku. ...

  2. 利用备份技术获取apk本地存储数据

    即使设备没有root,我们也可以通过物理访问设备来获取应用程序的数据,我们还可以通过此方法改变一个应用程序的数据.如果一个应用程序将数据存储在客户端, 使用简单的密码或pin检查,攻击者有可能使用这种 ...

  3. 20155213免考项目——简易的HIDAttack

    20155213免考项目--简易的HIDAttack 听5214说他做不出来自己的免考项目,于是就转向bof进阶,并且成功做出了64位的ROP攻击...... 既然如此,那我就再做一个吧,但都已经期末 ...

  4. Metasploit简单应用

    什么是Metasploit Metasploit是一款开源的安全漏洞检测工具. 它可以帮助用户识别安全问题,验证漏洞的缓解措施,并对某些软件进行安全性评估,提供真正的安全风险情报.当我们第一次接触Me ...

  5. face_recognition环境配置及命令行工具测试

    由于某种不可抗力(又是它!)我写了这篇博客,主要目的是记录. face_recognition是啥子? face_recognition号称世界上最简单的人脸识别库,可使用 Python 和命令行进行 ...

  6. WPF样式(Style)入门

    原文:WPF样式(Style)入门 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34802416/article/details/78231 ...

  7. MySql+Socket 完成数据库的增查Demo

    需求: 利用MySql数据库结合前端技术完成用户的注册(要求不使用Web服务技术),所以 Demo采用Socket技术实现Web通信. 第一部分:数据库创建 数据库采用mysql 5.7.18, 数据 ...

  8. [Deep-Learning-with-Python] Keras高级概念

    Keras API 目前为止,介绍的神经网络模型都是通过Sequential模型来实现的.Sequential模型假设神经网络模型只有一个输入一个输出,而且模型的网络层是线性堆叠在一起的. 这是一个经 ...

  9. MySQL清理慢查询日志slow_log的方法

    一.清除原因 因为之前打开了慢查询,导致此表越来越大达到47G,导致磁盘快被占满,使用xtrabackup进行备份的时候文件也超大. mysql> show variables like 'lo ...

  10. asp.net mvc2+nhibernate实体类映射问题之“尝试创建Controller类型的控制器时出错请确保控制器具有无参数公共构造函数”

    程序出了问题,解决后发现如此简单,犯的错误是如此的低级啊,特此记录! 运行程序总是在浏览器中看到一片空白,什么也没有,用application_error跟踪发现抓出一个这样的异常 然后浏览器中就是这 ...