给出二维平面
$opt1.$ 对点 $(x, y)$ 增减颜色 $c$,
$opt2.$ 询问矩形 $(1, y_1), (x, y_2)$ 内出现过的颜色种数
$x, y <= 1e6, c <= 50$

二维线段树 $hehe$

观察特殊性质每次询问的矩形的左上(下)角都在直线 $x = 1$ 上

假设只有一种颜色
如下平面直角坐标系

这张图貌似并没有什么用

给出黑色点为插入的点
询问绿色矩形内的颜色种数
因为假设只有 $1$ 种颜色
所以只需判断绿色矩形内是否存在插入的点

显然是存在的

Sol
每次插入一个点 $(x, y)$,把 $x$ 当做 $y$ 的权值,线段树维护每个 $y$ 的最小值
即线段树以纵坐标 $y$ 为下标,维护每个数的最小值
相当于单点修改 $y$ 的值为 $min(w_y, x)$
这也就是询问的矩形左上(下)点的特殊性质所在

这样的话
对每个颜色开一颗线段树(动态开点)
每次查询,枚举颜色,线段树查询区间 $(y_1, y_2)$ 内的最小值 $Min$
如果 $Min <= $ 右上(下)点的横坐标则对答案贡献为 $1$

时间复杂度 $O(50nlogn)$

注意:线段树在查询时,如果当前最小值已经 $<=$ 查询的 $x$ 时,不再进行递归
否则会 $TLE$,可能下面的code写都丑

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std;
const int N = 1e6 + ; #define gc getchar()
inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
}
#undef gc int Root[], Lson[N * ], Rson[N * ], Minx[N * ];
int js_root; void Clear() {
js_root = ;
memset(Root, , sizeof Root);
memset(Lson, , sizeof Lson);
memset(Rson, , sizeof Rson);
memset(Minx, 0x3f, sizeof Minx);
} void Poi_G(int l, int r, int &jd, int x, int num) {
if(!jd) jd = ++ js_root;
Minx[jd] = min(Minx[jd], num);
if(l == r) return ;
int mid = (l + r) >> ;
if(x <= mid) Poi_G(l, mid, Lson[jd], x, num);
else Poi_G(mid + , r, Rson[jd], x, num);
} int Ans; void Sec_A(int l, int r, int jd, int x, int y, int imp) {
if(!jd || Ans <= imp) return ;
if(x <= l && r <= y) {Ans = min(Ans, Minx[jd]); return ;}
if(l == r) return ;
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, Lson[jd], x, y, imp);
if(y > mid) Sec_A(mid + , r, Rson[jd], x, y, imp);
} int main() {
int opt;
memset(Minx, 0x3f, sizeof Minx);
while(scanf("%d", &opt)) {
if(opt == ) break;
else if(opt == ) Clear();
else if(opt == ) {
int x = read(), y = read(), c = read();
Poi_G(, N - , Root[c], y, x);
} else {
int x = read(), y_1 = read(), y_2 = read(), Out_Ans();
if(y_1 > y_2) std:: swap(y_1, y_2);
for(int i = ; i <= ; i ++) {
Ans = Minx[N - ];
Sec_A(, N - , Root[i], y_1, y_2, x);
if(Ans <= x) Out_Ans ++;
}
printf("%d\n", Out_Ans);
}
}
return ;
}

hdu 6183的更多相关文章

  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 暴力,线段树动态开点,cdq分治

    B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...

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

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

  5. 【刷题】HDU 6183 Color it

    Problem Description Do you like painting? Little D doesn't like painting, especially messy color pai ...

  6. HDU 6183 Color it

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

  7. HDU - 6183:Color it (线段树&动态开点||CDQ分治)

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

  8. HDU - 6183 动态开点线段树 || 令人绝望的线段树

    一看C才[0,50],肯定要开51棵线段树维护y区间的最小x值啦 是男人就上51棵..等等空间爆几倍了 动态开点!51棵线段树用全局节点变量控制,有点像主席树 清空工作很简单,把51个树根清掉然后回收 ...

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

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

随机推荐

  1. mouseenter 与 mouseover 区别于选择

    mouseover事件, 箭头在子元素移动会触发冒泡事件,  子元素的鼠标箭头可触父元素方法, 相反,mouseenter事件功能与mouseover类似, 但鼠标进入某个元素不会冒泡触发父元素方法. ...

  2. jquery中checkbox的全选与反选

    <!DOCTYPE html><html><head> <meta charset="utf-8" /> <title> ...

  3. 【转载】 Asp.Net MVC网站提交富文本HTML标签内容抛出异常

    今天开发一个ASP.NET MVC网站时,有个页面使用到了FCKEditor富文本编辑器,通过Post方式提交内容时候抛出异常,仔细分析后得出应该是服务器阻止了带有HTML标签内容的提交操作,ASP. ...

  4. echarts字体适配

    var html = document.getElementsByTagName("html")[0]; var width = html.clientWidth; var too ...

  5. .NET 对文件和文件夹操作的介绍

    1 Directory和File类只包含静态方法,不能被实例化 2 DirectoryInfo和FileInfo他们是有状态的,需要被实例化 //构造函数初始化一个文件的路径 FileInfo myF ...

  6. stm32 SD卡

    容量等级 SD容量有8MB.16MB.32MB.64MB.128MB.256MB.512MB.1GB.2GB SDHC容量有2GB .4GB.8GB.16GB.32GB SDXC容量有32GB.48G ...

  7. SAP Marketing Cloud功能简述(二) : Target Group

    这个系列的第一篇文章 SAP Marketing Cloud功能简述(一) : Contacts和Profiles,我向大家介绍了SAP Marketing Cloud里的Contacts和Profi ...

  8. Linux/Aix日常报错整理

    [root@localhost ~]# umount /mnt umount.nfs: /mnt: device is busy umount.nfs: /mnt: device is busy 问题 ...

  9. Android笔记(三十二) Android中线程之间的通信(四)主线程给子线程发送消息

    之前的例子都是我们在子线程(WorkerThread)当中处理并发送消息,然后在主线程(UI线程)中获取消息并修改UI,那么可以不可以在由主线程发送消息,子线程接收呢?我们按照之前的思路写一下代码: ...

  10. 数组中的filter,every,some,find,findIndex

    这些都是es5中数组新增的方法,一旦用到还是觉得挺实用的 var arr = [0,12,4,6,8]; var res = arr.filter(function(item,index,Arr){ ...