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.

0 0

: clear all the points.

1 1

x x

y y

c c

: add a point which color is c c

at point (x,y) (x,y)

.

2 2

x x

y 1  y1

y 2  y2

: 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 c c

, that 1≤a≤x 1≤a≤x

and y 1 ≤b≤y 2  y1≤b≤y2

, then the color c c

should be counted.

3 3

: exit.

InputThe input contains many lines.

Each line contains a operation. It may be '0', '1 x y c' ( 1≤x,y≤10 6 ,0≤c≤50 1≤x,y≤106,0≤c≤50

), '2 x y1 y2' (1≤x,y 1 ,y 2 ≤10 6  1≤x,y1,y2≤106

) or '3'.

x,y,c,y1,y2 x,y,c,y1,y2

are all integers.

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

There are at most 150000 150000

continuous operations of operation 1 and operation 2.

There are at most 10 10

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

题意:给定一个1e6*1e6的矩阵,有四种操作,0是清空矩阵;1是给某点加一个颜色c;2是查询某个区间(1,y1)到(x2,y2)的颜色数,3是退出。

思路:由于矩阵位置的特殊性,都是x=1开始,那么我们就是查询每种颜色在区间(y1,y2)是否有点的最小值小于x2。 用线段树维护区间最小值,动态开点。

(日后来补CDQ分治。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
struct in{
int l,r,v;
in(){l=r=v=;}
}s[maxn<<]; int rt[],cnt;
void update(int &Now,int L,int R,int pos,int val)
{
if(!Now) Now=++cnt,s[Now].v=val;
s[Now].v=min(s[Now].v,val);
if(L==R) return ; int Mid=(L+R)>>;
if(pos<=Mid) update(s[Now].l,L,Mid,pos,val);
else update(s[Now].r,Mid+,R,pos,val);
}
bool query(int Now,int L,int R,int l,int r,int pos)
{
if(!Now) return false;
if(l<=L&&r>=R) return s[Now].v<=pos;
int Mid=(L+R)>>;
if(l<=Mid) if(query(s[Now].l,L,Mid,l,r,pos)) return true;
if(r>Mid) if(query(s[Now].r,Mid+,R,l,r,pos)) return true;
return false;
}
int main()
{
int opt,x1,y1,x2,y2,c;
while(scanf("%d",&opt)){
if(opt==){
rep(i,,) rt[i]=;
rep(i,,cnt) s[i].l=s[i].r=s[i].v=;cnt=;
}
else if(opt==){
scanf("%d%d%d",&x1,&y1,&c);
update(rt[c],,,y1,x1);
}
else if(opt==){
scanf("%d%d%d",&x2,&y1,&y2); int ans=;
rep(i,,) ans+=query(rt[i],,,y1,y2,x2);
printf("%d\n",ans);
}
else break;
}
return ;
}

HDU - 6183:Color it (线段树&动态开点||CDQ分治)的更多相关文章

  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 (线段树 动态开点)

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

随机推荐

  1. boot空间不足,删除Ubuntu旧内核

    0 Problem 今天打开电脑的时候ubuntu提示boot空间不足.查了资料,原来Ubuntu的自动升级并没有删除系统的旧内核,于是boot下旧的内核文件越积越多,最后就满了. 1 Solutio ...

  2. [国家集训队] calc(动规+拉格朗日插值法)

    题目 P4463 [国家集训队] calc 集训队的题目真是做不动呀\(\%>\_<\%\) 朴素方程 设\(f_{i,j}\)为前\(i\)个数值域\([1,j]\),且序列递增的总贡献 ...

  3. uiautomator-CTS上运行,出xml报告

      一.CTS 介绍与命令说明 主要介绍: CTS下载与配置 CTS目录说明 CTS基本命令说明 Windows系统下运行CTSCTS 全称Compatibility Test Suite 兼容性测试 ...

  4. Spring_使用 JdbcTemplate和JdbcDaoSupport

  5. TP多条件sql查询,分组排序

    $k=M('order a'); $bj=$k->join("left join __CHANGE__ b on b.tb_name='order'and a.order_id=b.t ...

  6. Android -- junit测试框架,logcat获取log信息

    1. 相关概念 白盒测试: 知道程序源代码. 根据测试的粒度分为不同的类型   方法测试 function test         单元测试 unit test                 集成 ...

  7. NumPy数组属性

    NumPy - 数组属性 这一章中,我们会讨论 NumPy 的多种数组属性. ndarray.shape 这一数组属性返回一个包含数组维度的元组,它也可以用于调整数组大小. 示例 1 import n ...

  8. JNI_Z_04_属性的操作(非String类型的属性)

    1.步骤 : (1).获取 jclass (2).获取 类属性字段的id(最后一个参数是 属性字段 的签名) (3).获取/设置 类属性字段的值 ZC: 貌似 JNI里面 操作 类属性字段,完全是 无 ...

  9. 数据库连接池 c3p0 druid

    druid 数据库连接池 c3p0 使用C3P0数据源时需要依赖 mchange-commons-java-0.2.3.4.jar包.缺少该jar包则会报错!

  10. flask学习(一):环境的安装

    一. 安装python2.7 从python官网下载python2.7的版本 双击python2.7,然后选择安装路径,一直下一步就可以了 设置环境变量,把python和pip的安装路径添加到PATH ...