hdu 6183
给出二维平面
$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的更多相关文章
- HDU 6183 Color it 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...
- HDU 6183 Color it(动态开点线段树)
题目原网址:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题目中文翻译: Time Limit: 20000/10000 MS (Java/Others ...
- HDU - 6183 暴力,线段树动态开点,cdq分治
B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...
- hdu 6183 Color it (线段树 动态开点)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- 【刷题】HDU 6183 Color it
Problem Description Do you like painting? Little D doesn't like painting, especially messy color pai ...
- HDU 6183 Color it
线段树. 假设只有一种颜色,因为每次询问有一个$x$一定是$1$,那么我可以想办法找出每一个$y$最小的$x$是多少,如果最小的都不符合,那么一定不符合,因为更新变成了单点更新,询问是区间询问最小值, ...
- HDU - 6183:Color it (线段树&动态开点||CDQ分治)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- HDU - 6183 动态开点线段树 || 令人绝望的线段树
一看C才[0,50],肯定要开51棵线段树维护y区间的最小x值啦 是男人就上51棵..等等空间爆几倍了 动态开点!51棵线段树用全局节点变量控制,有点像主席树 清空工作很简单,把51个树根清掉然后回收 ...
- HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Pro ...
随机推荐
- hadoop 完全分布式搭建总结
完全分布式--------------- 1.配置文件 [core-site.xml] hdfs 地址 fs.defaultFS=hdfs://s129:8020/ [hdfs-site.xml] 副 ...
- idea的项目结构
idea项目结构: 一般是创建一个empty project,然后再创建一个个的Module.
- oracle给用户授权存储过程
https://www.jianshu.com/p/fab356d68ae2 grant connect,resource to xinomonitor; 发现不能进行断点调试,然后授如下权限 gra ...
- PyCharm 占用过大 C 盘空间,system 配置文件迁移
随着 PyCharm 的持续使用,对应 C:\Users\<username>\.PyCharm<2018.3> 下的文件大小会持续增大,且通常为 system 文件夹下的内容 ...
- template中实现加减乘除数学运算
django模板只提供了加法的filter,没有提供专门的乘法和除法运算:django提供了widthratio的tag用来计算比率,可以变相用于乘法和除法的计算. # 加法{{value|add:1 ...
- jquery判断数据类型源码解读
var class2type = {}; ("Boolean Number String Function Array Date RegExp Object Error").spl ...
- UI5-技术篇-Expand与Deep 服务测试
1.SEGW创建服务 2.创建Data Model 2.1Entity Types ZRICO_USR 设置主键.排序字段.过滤字段 ZRICO_USRITM设置主键 2.2Associations ...
- ssh免密登陆(简单快捷)
介绍免密登陆配合下边这张图可以了解下过程: 假设现在A要通过免密登陆B 在A上的操作: 1.终端输入ssh-keygen (后边可以指定加密算法:-t 算法,如果不指定就是默认的rsa) 原理: 首先 ...
- dao 接口定义了一个方法,报错 The method xxx is undefined for the type xxx;
转自:https://blog.csdn.net/panshoujia/article/details/78203837 持久层(DAO层)下的一个接口 ,eclipse报了一个The method ...
- pycharm连接数据库
今天说说如何使用pycharm连接oracle数据库 1.首先你需要安装oracle数据库 2.在pycharm中安装cx_Oracle.在file->settings->Project- ...