HDU - 6183:Color it (线段树&动态开点||CDQ分治)
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分治)的更多相关文章
- HDU - 6183 暴力,线段树动态开点,cdq分治
B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...
- hdu6183 Color it 线段树动态开点+查询减枝
题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形 ...
- HDU 6183 Color it 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...
- HDU6183 Color it (线段树动态开点)
题意: 一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色 思路: 建立50颗线段树,对每个颜色的线段树,维护每个y坐标上 ...
- BZOJ_4636_蒟蒻的数列_线段树+动态开点
BZOJ_4636_蒟蒻的数列_线段树+动态开点 Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将 ...
- P3939 数颜色 线段树动态开点
P3939 数颜色 线段树动态开点 luogu P3939 水.直接对每种颜色开个权值线段树即可,注意动态开点. #include <cstdio> #include <algori ...
- 洛谷P3313 [SDOI2014]旅行 题解 树链剖分+线段树动态开点
题目链接:https://www.luogu.org/problem/P3313 这道题目就是树链剖分+线段树动态开点. 然后做这道题目之前我们先来看一道不考虑树链剖分之后完全相同的线段树动态开点的题 ...
- codedecision P1113 同颜色询问 题解 线段树动态开点
题目描述:https://www.cnblogs.com/problems/p/11789930.html 题目链接:http://codedecision.com/problem/1113 这道题目 ...
- hdu 6183 Color it (线段树 动态开点)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
随机推荐
- Selenium WebDriver 2.34.0 发布,支持Firefox22
Selenium WebDriver 2.34.0 发布,支持Firefox22http://automationqa.com/forum.php?mod=viewthread&tid=270 ...
- 搭建自己的npm仓库
第一步:安装Erlang环境 首先,安装必要的库 yum install build-essential yum install libncurses5-dev yum install libssl- ...
- js 三元表达式 复杂写法
a = 0 b = 0 a === 0 && (a = 1,b = 2) a === 1 ? (a = 3,alert(b)) : (b = 4) a === 1 || alert(a ...
- 【hihocoder】三十九周:二分.归并排序之逆序对
就是用归并排序求数组中得逆序对.假设数组为a:[2 4 5],和b:[1 3],那么在这一次归并的时候逆序对这样求,belement表示当前result数组中b数组对应的元素个数,total表示逆序对 ...
- uvm学习杂记
一个类,只定义了而没有实例化,是没有任何意义的,但也有特殊情况,对于一个静态类,即其成员变量都是静态的,不实例化也可以正常使用: 类要想和DUT通信,不能在类里定义接口,会报错,只能在类里定义虚拟接口 ...
- Linux下捕捉信号
关于 信号signal的知识铺垫 点这里 信号由三种处理方式: 忽略 执行该信号的默认处理动作 捕捉信号 如果信号的处理动作是用户自定义函数,在信号递达时就调用这个自定义函数,这称为捕捉信号. 进程收 ...
- Book Review of “The practice of programming” (Ⅳ)
The practice of programming Chapter 4 Interfaces A good programmer should always be good at designin ...
- The revocation function was unable to check revocation for the certificate
https://stackoverflow.com/questions/45556189/git-the-revocation-function-was-unable-to-check-revocat ...
- 带你彻底明白 Android Studio 打包混淆
前言 在使用Android Studio混淆打包时,该IDE自身集成了Java语言的ProGuard作为压缩,优化和混淆工具,配合Gradle构建工具使用很简单.只需要在工程应用目录的gradle文件 ...
- flash滚动图片遮住二级下拉菜单解决方法
如上图所示,在进行排版时,如果不注意会遇到二级下拉菜单被下边的img图片遮住.此种情况在ie7 8 中出现. 解决方法:给二级下拉菜单添加z-index:9999;position:relative; ...