Problem Description

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 : clear all the points.

1 x y c : add a point which color is c at point (x,y).

2 x y1 y2 : count how many different colors in the square (1,y1) and (x,y2). That is to say, if there is a point (a,b) colored c, that 1≤a≤x and y1≤b≤y2, then the color c should be counted.

3 : exit.

Input

The input contains many lines.

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

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

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

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

There are at most 10 operation 0.

Output

For 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

Description(CHN)

\(1~x~y~c\) :在 \((x,y)\) 点涂上c这种颜色

\(2~x~y_1~y_2\) :从矩形左下角 \((1,y_1)\) 到矩形右上角 \((x,y_2)\) 范围内有多少种颜色

\(0\) :清空

\(3\) :表示退出

Solution

考虑对每一种颜色建一棵线段树

询问时枚举每一种颜色,看是否存在矩阵中

因为询问一定是从 \(x=1\) 开始,所以对于一种颜色,线段树位置 \(i\) 表示矩形 \(y=i\) 的那一列中当前颜色出现的最小 \(x\) 是什么,再与询问的条件比较即可

空间开不下,用动态开点

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=1000000+10,inf=0x3f3f3f3f;
int opt,N=MAXN,C=50,na;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return (x<y?x:y);}
template<typename T> inline T max(T x,T y){return (x>y?x:y);}
#define Mid ((l+r)>>1)
#define lson l,Mid
#define rson Mid+1,r
struct Segment_Tree{
int Mn[MAXN<<2],lc[MAXN<<2],rc[MAXN<<2],cnt,root[50+10];
inline void init()
{
for(register int i=0;i<=cnt;++i)lc[i]=rc[i]=0;
memset(root,0,sizeof(root));
cnt=0;
}
inline void Update(int &rt,int l,int r,int ps,int k)
{
if(!rt)Mn[rt=++cnt]=k;
else chkmin(Mn[rt],k);
if(l==r)return ;
else
{
if(ps<=Mid)Update(lc[rt],lson,ps,k);
else Update(rc[rt],rson,ps,k);
}
}
inline void Query(int rt,int l,int r,int L,int R,int lt)
{
if(!rt||na)return ;
if(L<=l&&r<=R)na=(Mn[rt]<=lt);
else
{
if(L<=Mid)Query(lc[rt],lson,L,R,lt);
if(R>Mid)Query(rc[rt],rson,L,R,lt);
}
}
};
Segment_Tree T;
#undef Mid
#undef lson
#undef rson
int main()
{
while(scanf("%d",&opt)!=EOF&&opt!=3)
{
if(opt==0)T.init();
if(opt==1)
{
int x,y,c;read(x);read(y);read(c);
T.Update(T.root[c],1,N,y,x);
}
if(opt==2)
{
int x,y1,y2,ans=0;read(x);read(y1);read(y2);
if(y1>y2)std::swap(y1,y2);
for(register int i=0;i<=C;++i)na=0,T.Query(T.root[i],1,N,y1,y2,x),ans+=na;
write(ans,'\n');
}
}
return 0;
}

【刷题】HDU 6183 Color it的更多相关文章

  1. HDU 6183 Color it 线段树

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

  2. HDU 6183 Color it(动态开点线段树)

    题目原网址:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题目中文翻译: Time Limit: 20000/10000 MS (Java/Others ...

  3. hdu 6183 Color it (线段树 动态开点)

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

  4. HDU 6183 Color it cdq分治 + 线段树 + 状态压缩

    Color it Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Pro ...

  5. HDU 6183 Color it

    线段树. 假设只有一种颜色,因为每次询问有一个$x$一定是$1$,那么我可以想办法找出每一个$y$最小的$x$是多少,如果最小的都不符合,那么一定不符合,因为更新变成了单点更新,询问是区间询问最小值, ...

  6. 教你用python写:HDU刷题神器

    声明:本文以学习为目的,请不要影响他人正常判题 HDU刷题神器,早已被前辈们做出来了,不过没有见过用python写的.大一的时候见识了学长写这个,当时还是一脸懵逼,只知道这玩意儿好屌-.时隔一年,决定 ...

  7. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU 自动刷题机 Auto AC (轻轻松松进入HDU首页)

    前言: 在写这篇文章之前,首先感谢给我思路以及帮助过我的学长们 以下4篇博客都是学长原创,其中有很多有用的,值得学习的东西,希望能够帮到大家! 1.手把手教你用C++ 写ACM自动刷题神器(冲入HDU ...

  9. 手把手教你用C++ 写ACM自动刷题神器(冲入HDU首页)

    转载注明原地址:http://blog.csdn.net/nk_test/article/details/49497017 少年,作为苦练ACM,通宵刷题的你 是不是想着有一天能够荣登各大OJ榜首,俯 ...

随机推荐

  1. 初学者下载使用Python遇到的问题看它就行了

    首先在python管网(www.python.org)中找到对应的版本与系统,以(window7系统64位python3.7.3为例) 打开电脑--打开浏览器--输入www.python.org--d ...

  2. 导入Cardboard SDK后Build到安卓平台出错:Unable to merge android manifests. (已解决)

    报错说“Unable to merge android manifests. See the consoler for more details.” 解决方法: 打开SDK Manager ,安装An ...

  3. 来源自rnnoise,但非rnn

    很快又一年过去了. 自学音频算法也近一年了. 不记得有多少个日日夜夜, 半夜醒来,就为验证算法思路. 一次又一次地改进和突破. 傻逼样的坚持,必然得到牛逼样的结果. 这一年,主要扎音频算法上. 经常有 ...

  4. FFmpeg+vs2013开发环境配置(windows)

    1.下载ffmpeg包(dll.include.lib)   https://ffmpeg.zeranoe.com/builds/         有3个版本:Static.Shared和Dev St ...

  5. 本地使用js或jquery操作cookie在谷歌浏览器chrome中不生效

    一般是在本地调试cookie,无论使用jquery cookie插件还是js原生态cookie方法,在谷歌浏览器chrome中都不生效,这是什么原因? 原因是: chrome不支持js在本地操作coo ...

  6. 电梯调度 结对项目开发(郭林林&胡潇丹)

    (一)需求分析: 上升,下降,开门,关门: 超过负载以后发出警报,下去乘客: 电梯出现故障后,电梯停止: 电梯楼层的输入框可以同时指定所要到的楼层,也是楼层的显示框: 电梯同时记录多个状态,即为到达多 ...

  7. 【RL系列】Multi-Armed Bandit问题笔记

    这是我学习Reinforcement Learning的一篇记录总结,参考了这本介绍RL比较经典的Reinforcement Learning: An Introduction (Drfit) .这本 ...

  8. XSS构造技巧

    利用字符编码: 百度曾经出过一个XSS漏洞,在一个<script>标签中输出一个变量,其中转义了双引号: var redirectUrl="\";alert(/XSS/ ...

  9. 配置Ubuntu16.04虚拟机 (用途:CTF_pwn)

    因为学习需要16.xx的虚拟机,所以把之前18.04的Ubuntu卸掉重装了一遍Ubuntu16.04, 考虑到我有备份和重装系统的爱好,故记之,以备后用. 目录: //最后更新时间:190122·1 ...

  10. IOS上z-index和fixed定位无效

    IOS上z-index和fixed定位无效 在该元素上加: -webkit-transform:translateZ(1px); -moz-transform:translateZ(1px); -o- ...