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

  1. 0
  2. 1 1000000 1000000 50
  3. 1 1000000 999999 0
  4. 1 1000000 999999 0
  5. 1 1000000 1000000 49
  6. 2 1000000 1000000 1000000
  7. 2 1000000 1 1000000
  8. 0
  9. 1 1 1 1
  10. 2 1 1 2
  11. 1 1 2 2
  12. 2 1 1 2
  13. 1 2 2 2
  14. 2 1 1 2
  15. 1 2 1 3
  16. 2 2 1 2
  17. 2 10 1 2
  18. 2 10 2 2
  19. 0
  20. 1 1 1 1
  21. 2 1 1 1
  22. 1 1 2 1
  23. 2 1 1 2
  24. 1 2 2 1
  25. 2 1 1 2
  26. 1 2 1 1
  27. 2 2 1 2
  28. 2 10 1 2
  29. 2 10 2 2
  30. 3

Sample Output

  1. 2
  2. 3
  3. 1
  4. 2
  5. 2
  6. 3
  7. 3
  8. 1
  9. 1
  10. 1
  11. 1
  12. 1
  13. 1
  14. 1
  15.  
  16. 思路:
    50种颜色,对每一种颜色建一颗线段树维护,动态开点。
    第一种操作:使点(x,y)的颜色变为c
    第二种:询问(1y1),(x,y2)两点间的颜色种类数量
    我们可以以y轴建线段树,横坐标为值,那么要确定两点之前是否存在某种颜色,只要询问下每个颜色在y1,y2之间最小的值(也就是横坐标).判断下最小值是否小于第二种操作给出的x,如果小于的话就代表两点间存在这种颜色。
  17.  
  18. 实现代码:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define mid int m = (l + r) >> 1
  5. const int M = 1e6+;
  6. int n = 1e6,flag=;
  7. int sum[M],ne=,ls[M],rs[M],rt[];
  8.  
  9. void update(int &k,int l,int r,int p,int num){
  10. if(!k){ //如果当前区间未拓展,拓展并赋值
  11. k = ++ne;
  12. sum[k] = num;
  13. }
  14. sum[k] = min(sum[k],num);//当前区间有值,更新下最小值
  15. if(l == r)
  16. return ;
  17. mid;
  18. if(p <= m) update(ls[k],l,m,p,num);
  19. else update(rs[k],m+,r,p,num);
  20. }
  21.  
  22. void query(int k,int L,int R,int l,int r,int up){
  23. if(!k||flag) return ;
  24. if(L <= l&&R >= r){
  25. if(sum[k]<=up)
  26. flag = ;
  27. return;
  28. }
  29. mid;
  30. if(L <= m) query(ls[k],L,R,l,m,up);
  31. if(R > m) query(rs[k],L,R,m+,r,up);
  32. return ;
  33. }
  34.  
  35. void init(){
  36. memset(rt,,sizeof(rt));
  37. memset(sum,,sizeof(sum));
  38. memset(ls,,sizeof(ls));
  39. memset(rs,,sizeof(rs));
  40. ne = ;
  41. }
  42. int main()
  43. {
  44. int op,x,y,z;
  45. while(~scanf("%d",&op)){
  46. if(op == )
  47. init();
  48. else if(op == ){
  49. scanf("%d%d%d",&x,&y,&z);
  50. update(rt[z],,n,y,x);
  51. }
  52. else if(op == ){
  53. scanf("%d%d%d",&x,&y,&z);
  54. int ans = ;
  55. for(int i = ;i <= ;i ++){
  56. flag = ;
  57. query(rt[i],y,z,,n,x);
  58. if(flag) ans++;
  59. }
  60. printf("%d\n",ans);
  61. }
  62. else return ;
  63. }
  64. return ;
  65. }

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. C#数组、js数组、json

    C#数组 参考地址C#之数组 什么是数组?数组是一种数据结构,包含同一个类型的多个元素.数组的声明:int[] myIntArray; 注:声明数组时,方括号 [] 必须跟在类型后面,而不是变量名后面 ...

  2. Oracle 解决【ORA-01704:字符串文字太长】

    错误提示:oracle在toad中执行一段sql语句时,出现错误‘ORA-01704:字符串文字太长’.如下图: 原因:一般为包含有对CLOB字段的数据操作.如果CLOB字段的内容非常大的时候,会导致 ...

  3. 带你看懂大数据采集引擎之Flume&采集目录中的日志

    一.Flume的介绍: Flume由Cloudera公司开发,是一种提供高可用.高可靠.分布式海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于采集数据:同时,flum ...

  4. 大数据入门第二十四天——SparkStreaming(二)与flume、kafka整合

    前一篇中数据源采用的是从一个socket中拿数据,有点属于“旁门左道”,正经的是从kafka等消息队列中拿数据! 主要支持的source,由官网得知如下: 获取数据的形式包括推送push和拉取pull ...

  5. CS100.1x-lab3_text_analysis_and_entity_resolution_student

    这次作业叫Text Analysis and Entity Resolution,比前几次作业难度要大很多.相关ipynb文件见我github. 实体解析在数据清洗和数据整合中是一个很重要,且有难度的 ...

  6. 几个不常用的 Web API

    1. 设备震动 vibrate Navigator.vibrate() 方法使设备(有震动硬件)产生有频率的震动.若设备不支持震动,该方法将无效.若某震动方式已经在进行中(当该方法调用时),则前一个震 ...

  7. js之浅拷贝与深拷贝

    浅拷贝:只会复制对象的第一层数据 深拷贝:不仅仅会复制第一层的数据,如果里面还有对象,会继续进行复制,直到复制到全是基本数据类型为止 简单来说,浅拷贝是都指向同一块内存区块,而深拷贝则是另外开辟了一块 ...

  8. R实战 第八篇:重塑数据(reshape2)

    数据重塑通常使用reshape2包,reshape2包用于实现对宽数据及长数据之间的相互转换,由于reshape2包不在R的默认安装包列表中,在第一次使用之前,需要安装和引用: install.pac ...

  9. Execute SQL Task 如何返回结果数据集

    Execute Sql Task的Result DataSet 主要有以下四种,当Execute Sql Task返回结果之后,需要使用SSIS Variable 来接收数据. 例子中使用的数据表代码 ...

  10. Android中级教程之----Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)

    在Android群里,经常会有人问我,Android Log是怎么用的,今天我就把从网上以及SDK里东拼西凑过来,让大家先一睹为快,希望对大家入门Android Log有一定的帮助. android. ...