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 ...
随机推荐
- Generative model 和Discriminative model
学习音乐自动标注过程中设计了有关分类型模型和生成型模型的东西,特地查了相关资料,在这里汇总. http://blog.sina.com.cn/s/blog_a18c98e50101058u.html ...
- module.exports和exports得区别
对module.exports和exports的一些理解 可能是有史以来最简单通俗易懂的有关Module.exports和exports区别的文章了. exports = module.exports ...
- return false 和 return true
常规用法 在普通函数中:return 语句终止函数的执行,并返回一个指定的值给函数调用者,一般会用一个变量接收这个返回值再进行其它处理.如果未指定返回值,则返回 undefined 其中,返回一个函数 ...
- vue移动端 滚动 鼠标按下效果
<div class="item" :id="item.RowID" @touchstart="touchstart(item.RowID)&q ...
- C++添加简单的日记记录
#include<fstream>#include<iostream> using namespace std;//这是一种日记记录 b 种void LOG(char *tx, ...
- Django学习笔记之Django视图View
一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XML文档,或者一张图片. ...
- Boot-Repair&usb_repair
https://help.ubuntu.com/community/Boot-Repair https://askubuntu.com/questions/500647/unable-to-mount ...
- fabric查看本地与远程主机信息
#!/usr/bin/pythonfrom fabric.api import *env.user='root'env.hosts=['172.10.224.183','172.10.224.132' ...
- spring security使用哈希加密的密码
之前我们都是使用MD5 Md5PasswordEncoder 或者SHA ShaPasswordEncoder 的哈希算法进行密码加密,在spring security中依然使用只要指定使用自定义加密 ...
- Hibernate -- 对象关系映射基础