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 ...
随机推荐
- addEventListener和attachEvent介绍, 原生js和jquery的兼容性写法
也许很多同仁一听到事件监听,第一想到的就是原生js的 addEventListener()事件,的确如此,当然如果只是适用于现代浏览器(IE9.10.11 | ff, chorme, safari, ...
- jQuery/CSS3 图片边框线条变换动画
在线演示 本地下载
- Spring AOP(5)-- 注解
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?><beans xml ...
- LeetCode——Fizz Buzz
LeetCode--Fizz Buzz Question Write a program that outputs the string representation of numbers from ...
- Sudoku Solver, 求数独
问题描述:填充数独表中空元素.空元素为'.' 算法分析:没填充一个数,都要看这个数所在的行,列,小矩阵是否合法.然后还要看整个数独表是否正确,而判断整个数独表只能通过递归,因为前一个结果的判断要依赖后 ...
- c++中的函数对象《未完成》
头文件: #pragma once #include<iostream> #include<vector> using namespace std; class Student ...
- hibernate学习(4)
Hibernate查询方式 1 对象导航查询 (1)根据id查询某个客户,再查询这个客户里面所有的联系人 2 OID查询 (1)根据id查询某一条记录,返回对象 3 hql查询 (1)Query对象, ...
- Android ADT远程主机强迫关闭了一个现有的连接 Connection attempts: 1 解决方法
adb有一个限制, 也可以说是bug. 当手机上同时运行的进程数大于64时, 就会引发adb奔溃. 更深层次的原因, 就是windows API的WaitForMultipleObjects所支持的 ...
- 【Hive】执行脚本
1.linux下执行hive sql脚本 (1)hive -e “sql语句” (2)hive -e “sql语句” >> xxx 将sql查出来的语句重定向到xxx文件中,会显示Ok和数 ...
- Flask ajax 动态html 的javascript 事件失效
$('.db_edit').click(function(){ $(".editdbproduct").val($(this).parent().parent().find('.e ...